

So 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.
What 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.