Traister101

Yo whatup

  • 2 Posts
  • 334 Comments
Joined 1 year ago
cake
Cake day: September 28th, 2023

help-circle


  • 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.





  • Okay so say your testing a brand new rocket engine idea. It uses a fuel nobody has tried to use before. So what you do is you figure out how much energy this fuel has and do some math to figure out how much you’ll need to take with you for the typical rocket. You design an engine for this spec or better and thoroughly test it to make sure it’s behaving like expected. You eventually mount it to a rocket and make sure in practice it behaves as you expect. Next you put a payload in the rocket and test it again. If at any point things don’t behave as expected you have to fix your whole model.

    SpaceX struggles to go a launch without their engines destroying themselves. Perhaps they should go back a few steps?