• 0 Posts
  • 20 Comments
Joined 2 years ago
cake
Cake day: June 11th, 2023

help-circle








  • That’s the point, when programming with immutable structures you always pass the mutability onto the enclosing structure.

    I guess the point I was trying to make here was if the data type is already mutable, there is no point in sticking it in a list just so you can replace a reference with an identifier. You’re just adding an extra level of indirection. But sure yeah, if the type is inherently immutable, you have to do something.

    A list is an antipattern here IMO. Just wrap it in some dedicated object (see e.g. Java’s StringBuilder).

    Interesting. I’m not aware of anything like StringBuilder in the standard library for either Python or JavaScript. Looks like it wraps a list of characters and tries to behave as string-like as possible? You could presumably write your own class like that or download an implementation from someplace.

    I guess in most cases in my own code, where I need a mutable string is usually as part of a larger data structure which is the thing that gets passed around by reference, so it’s easy enough to replace a field within that.

    For building up a string, I would tend to use an io.StringIO in Python with file-writing calls, but those aren’t meant for sharing. What you don’t want to do is use the += operator a lot on strings. That gets expensive unless strings are mutable (like they are in say C++'s std::string).



  • As others have pointed out, there is the issue of breaking references to objects.

    There can also be a lot of memory thrashing if you have to keep reallocating and copying objects all the time. To some extent, that may be mitigated using an internment scheme for common values. In Python, for example, integers are immutable but they intern something like the first 100 or so iirc? But that doesn’t work well for everything.

    Any container you want to populate dynamically should probably be mutable to avoid O(N²) nastiness.




  • I had a chat with my American relatives at one point which began with me asking why it seems medical malpractice suits have such soaring high settlements compared to where I am in Canada? They explained it to me like this. Say a botched procedure leaves you requiring constant medical treatments for the rest of your life. You have to sue for any treatments you would otherwise have to pay out of pocket. Where you have a public healthcare system, the state would cover that. You may still sue for loss of employment if you are no longer able to work, say, but settlements tend to be orders of magnitude higher because of those additional costs. Unfortunately, this leads to a proliferation of bottom-feeding personal injury lawyers who try to get you to litigate and overstate your injuries to get bigger settlements.


  • We brought back a hamster for our daughter without realizing she was pregnant. After having a giant litter, we gave them all away…or at least we thought we did? A day or two later, I saw a wiggling in the shavings and out pops a head. Our eyes locked momentarily before she dived back down.

    Definitely the runt of the litter. Had all sorts of paranoia and cowered under things for most of her life. She was maybe a year old when my daughter came running up. “Guys, you gotta see Hester!” We rushed over and there she was, hanging from the bars at the top of the cage and swinging arm-to-arm across.

    We were so happy for her, finally getting past her inhibitions and leading her best hamster life. Then she was curled up dead the next morning.






  • One time I was in Mexico with my wife while our daughter was still a baby and the lady at the front desk of the hotel where we were staying offered us a crib we could borrow. It was a kind gesture, but I was a little concerned because the crib seemed wobbly. I realized there were some screws loose but though I had a multitool on me, the holes were stripped.

    So later, I was talking with a local and he’s like “I can fix that.” He comes over and pulls a pack of toothpicks out of his pocket. He sticks one into each hole and breaks it off so that it’s not sticking out anymore. Then he drives the screw back in. I shook the crib after that and it was rock solid!

    Now I always keep some toothpicks handy. Fast-forward to just this year. My daughter is now an adult living in a condo, and was complaining the screw popped out of a kitchen cabinet door when her roommate yanked on it too hard. “I can fix that.”