Hacker News new | past | comments | ask | show | jobs | submit login

Disclaimer: when I worked on Internet Explorer in its twilight years I built a fork of BingBot that surveyed JS API usage and delivered a report to a Partner-level SE, whom I was in awe of, that I shared a team-room with.

In my experience, Array.prototype.shift() had limited applications because it mutates the source-array. I gathered it exists because at the time it was specc’d in the late 1990s the other cool kids, bash and perl, both had had args shift and JS didn’t want to feel left-out.

How different would the world be today if Array.prototype.shift instead froze the array and returned a reference to a +1 slice of the array instead? There was a fantastic opportunity to introduce FP and immutability to a whole generation of software people - which we (as an industry) squandered to our detriment. Ultra-new languages like Go and Zig still default to in-place mutable data and it’s maddening!

What hath shell scripts wrought?




Do you think Array.prototype.push() also has limited applications? It too mutates the source array, but must be the most commonly used Array method there is. And the two combined make for a lovely FIFO.

Anyone is certainly free to use Array.prototype.slice() if they want a view.


What are you doing with arrays that mutating them is maddening and has limited applications? Is this some kind of a cult?


> Is this some kind of a cult?

Yes, it’s called Functional Programming.


Hey now. In that cult (of which I’m a member), mutation is definitely maddening but its application is by no means limited (which is a non-small factor in it being maddening).


I'd take mutability for an array as given. If I wanted functional style data structures I'd use them. Personally I see zero reason for immutability of an array, imagine every add/push had to create a new instance of the said array.


I would expect arrays to be immutable and list type not


Sounds like it would go about as well as making me appreciate Shakespeare by forcing me to read it. It didn't work at all.

Do you enjoy reasoning about stale references in react? Now you can experience this joy everywhere with the power of immutability.


I wouldn't say go is exactly ultra new




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: