4 ms·
Some more technical info that browsers nowadays have O(1) behavior when using Array.shift() [1]. [1] https://bugzilla.mozilla.org/show_bug.cgi?id=1348772 https
by melvinroest 2y ago
Some more technical info that browsers nowadays have O(1) behavior when using Array.shift() [1].
[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1348772 https://bugzilla.mozilla.org/show_bug.cgi?id=1348772
- DaiPlusPlus 2y agoDisclaimer: 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?
- dumbo-octopus 2y agoDo 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.
- pipe01 2y agoI wouldn't say go is exactly ultra new
- dchest 2y agoWhat are you doing with arrays that mutating them is maddening and has limited applications? Is this some kind of a cult?
- chatmasta 2y ago> Is this some kind of a cult? Yes, it’s called Functional Programming.
- eyelidlessness 2y agoHey 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).
- recursive 2y agoSounds 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.
- xxs 2y agoI'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.
- merb 2y agoI would expect arrays to be immutable and list type not