You cannot have a string argument, arguments and variables in JS don’t have a type. All you have in JS is objects. Actual functions, like full on function foo(){}
are still objects, like you can actually store data on the things.
Traister101
Yo whatup
- 0 Posts
- 68 Comments
JavaScript doesn’t have typed parameters or variables. The function expects a string and does things in the function body which converts the object into a string. JS shares this behavior with all dynamically typed languages and it’s extremely useful in some contexts and extremely frustrating in others. It’s down to what it’s being used for. Dynamic languages make excellent scripting languages, see Python really just being a souped up shell lang
It’s not a string argument though, it’s JS. You can argue it’s expected to be a string but like the rest of JS all you can know from the signature alone is that it takes an object. Hopefully your little ducky quacks the right way!
Even Java has streams and stuff. Course Java so it’s kind of weird (iterators are mutable and internally iterate the collection/whatever lazily) streams are lazy and only go through all the operations, mapping, filtering ect when you collect the elements somehow (like rust). JS is wild lol
Traister101@lemmy.todayto Programming@programming.dev•Vibe Coding is not an excuse for low-quality work9·20 days agoWhat ramdon ass language could they possibly be pulling out of their ass for you to he completely unable to write a for loop? I’ve yet to see a for loop, or really any sort of loop that doesn’t look pretty much exactly like the standard C style for loop
for(int x = 0; x < z; x++) { }
If you have a C style language with iterator for loops like C++, Java and friends you almost certainly have this syntax
for(int x : numbers) { }
Python has exclusively iterator for loops with this syntax
for x in range(z)
The only real difference is that instead of a colon
:
you use thein
token.At best I can see the need for a quick refresh on what the exact syntax is but if your a senior any languages you actually use should have a template for junk like this. I don’t think I’ve manually written a loop in ages, I just type out
iter
for an iterator for loop or when I rarely need an indexfori
and the rest gets stamped out for me.If your being tested on random languages you can simply just not be familiar with a language. I haven’t touched Zig once but I’d totally be down to learn it. Everybody whos got a couple languages under their belt knows how easy it is to pick up new ones.
Ah yes now I can… dereference a raw pointer (yes that’s essentially the only thing unsafe rust actually enables you to do, it doesn’t disable the borrow checker or anything else, it just allows you to play with pointers)
Traister101@lemmy.todayto Programming@programming.dev•[Noob here] Can someone explain to me the advantage of mutable objects?9·3 months agoSo your writing a game. This game has what I’m going to call “entities” which are the dynamic NPCs and such objects. So these objects are most easily conceptualized as mutable things. Why mutable? Well they move around, change states depending on game events ect. If this object is immutable you’d have to tie the in world representation to a new object, constantly just because it moved slightly or something else. This object is mutable not just because it’s easier to understand but there are even efficiency gains due to not needing to constantly create a new version just because it moved a little bit.
In contrast the object which holds the position data (in this case we’ll have 3 doubles x, y, z) makes a lot of sense as an immutable object. This kind object is small making it cheap to replace (it’s just 3 doubles, so 3*64 bits or a total of 24 bytes) and it’s representing something that naturally makes sense as being immutable, it’s a set of 3 numbers.
Now another comparison your typical dynamic array type container (this is your
std::vector
std::vec
ArrayList
and friends). These are mutable objects mainly due to efficiency (it’s expensive to copy the contents when adding new values) yet they also are easier to conceptualize when mutable. It’s an object containing a collection of stuff like a box, you can put things in, take stuff out but it’s still the same box, just it’s contents have changed. If these objects are immutable to put something into the box you must first create a brand new box, and create a copy of the old boxes contents, and then put your new item into the box. Every time. Sometimes this kind of thing makes sense but it’s certainly not a common situation.Some functional languages do have immutable data structures however in reality the compiler usually does some magic and ends up using a mutable type as it’s simply so much more efficient.
So what’s 0 do then? I’m okay with wacky indexes (I’ve used something with negative indexes for a end-index shorthand) but 0 has to mean something that’s actually useful. Using the index as the offset into the array seems to be the most useful way to index them.
If your joking yes, if your not Java and Java Script are seperate things.
Traister101@lemmy.todayto Programming@programming.dev•Rant: I wish more people stopped using Github3·4 months agoGithub outside of hosting the actual git repo largly just provides good routes for collaboration, namely issues, their PR system and some convenient rules on who is allowed to mess with branches and how (IE you can set master to only accept merges done via github themselves). CI is the real lock in far as your git repo is concerned cause that just won’t work at all on another host
Uninitalized memory (
int a;
with no assignment) vector of int vectors (IE a dynamicint[][]
) and attempting to finda
, anint
in the vector of vectors of int IEint
instead ofvector<int>
. I think the iterator type is correct but I’m not sure off the top of my head
Traister101@lemmy.todayto Programming@programming.dev•Malicious code injection by compromised pull request branch names22·5 months agoOkay? I’m well aware. I do so all the time
Traister101@lemmy.todayto Programming@programming.dev•Malicious code injection by compromised pull request branch names1·5 months ago/
is used to separate the same branch in different repos. For exampleorigin/main
andremote/main
. Surprising that the other stuff is legal though
Traister101@lemmy.todayto Programmer Humor@programming.dev•Next month is gonna be rough282·6 months agoYou don’t have to be religious to think a fat dude in some red clothes that magically travels around the world giving out presents to good children isn’t a fun yearly tradition. Frankly it’s kind of an overdramatic reaction to a small red hat overlaid onto an icon. Should configuration be provided to disable the functionally? Sure I don’t care, hell have it disabled by default I don’t mind but it’s stupid to make a huge stink about something so minor.
JetBrains has really nice Git integration. Interactive rebaseses and merges are quite pleasant but I’m still dipping into the command line to do stuff occasionally. Most commonly a
git reset HEAD~
cause I want to split a commit though I had to dig through the reflog the other day cause I suddenly realized I lost an important branch that ended up being over a hundred commits back.
Traister101@lemmy.todayto Programmer Humor@programming.dev•"GitHub CI is easy", he said. "It's just `bash` ", he said.4·6 months agoAct works out pretty good but you need to pass it a token and stuff so the actual github CLI bits can work which is kind of a hassle. It took me much too long to discover you need a classic token, the one from the github CLI app
gh auth token
won’t work.Edit: Ah! Also getting act setup involved getting docker setup which involved me enabling virtualization in my bios for what I swear is like the 4th time I’ve done so. Also because I’m on Windows (iirc at least) I had to setup WSL or just make a windows container ಠ_ಠ
Traister101@lemmy.todayto Programmer Humor@programming.dev•You seen the jank? I live in it.. molded by it...3·6 months agoI’d say in most cases that’s a sign something needs to be extracted into a separate function. Course sometimes code is just complicated and extracting only makes things harder to follow. Even then I’d much rather use early return than nested
if
s as those are significantly harder for me to follow.
Traister101@lemmy.todayto Programmer Humor@programming.dev•You seen the jank? I live in it.. molded by it...6·6 months agoMy code got much more readable when I learned about early returns lol
Traister101@lemmy.todayto Programming@programming.dev•The empire of C++ strikes back with Safe C++ proposal6·7 months agoNah standard libraries are great but C++ has a lot of… cruft. Maybe don’t plonk a lot of Rust in there despite all the positives
I can’t judge but wow. Impressive