Slice, Splice, and other ways of Discombobulating Your Arrays
If you're a bit like me, you're constantly mixing up slice and splice, mostly because whoever named them foolishly decided to use nearly indistinguishable words for two thematically-related operations. There is absolutely no good way to distinguish them - no funny puns, no thematic giveaways - so I'm making one right here right now:
Slice
Lasers
Its
Constituents
Eway
vs.
Splice
Politely
Lets
In
Components
Every time
The hope here, of course, being that the most awful anagrams possible will do something to jog your memory when it's 3am and you need to either LASER CONSTITUENTS AWAY or LET COMPONENTS IN.
Also difficult: figuring out where slice and splice do their slicing and splicing, and, very importantly, as one uses indexes and the other...doesn't. So, here we go: slice values declare where slice SLARTS and where it ENDS. While splice has a "p" in it, so it does its changes in Place.
Here's a handy graphic:
Ta-da! Now you know them forever.
Comments
Post a Comment