|
My memory is a leaking bucket. My typing however, is very fast. Take for example the substring function. I wouldn't know which one it is for JavaScript, Haxe, ActionScript3, C#, Java, Python, C, C++, PHP. I know I used it at one point for all of them. For languages like JavaScript, Java and C#, it's probably a method, so you can start typing. Might be substring(), might also be substr() or something like that. For Haxe, I thought it was not a method so I think it's either part of Std or StringTools. If I use autocomplete, I have it in a few seconds, and I can also see the documentation on the parameters. Is the second parameter an index or a length? To be honest I have no idea. And the good part is, thanks to autocomplete I don't need to know. Also, if you work in a big codebase, you can't know every class. Needing to dig through code seems such a waste of time. |
In JavaScript, there are both, and a third one besides, largely for reasons of historical accumulation and inconsistent implementation:
They’ve each got their strange nuances in behaviour (and, in so-ancient-you-certainly-don’t-care-about-them engines, cross-engine inconsistencies), so if you’re relying on autocomplete, it’s necessary that your autocomplete at the very least give some meaningful parameter names, because the difference between taking length and an end index is rather significant.Which one should you use? slice. It’s generally agreed to be the most reasonable of the three in what it does and how it works, and it matches Array.prototype.slice well. So: sorry that you thought it might be substring or substr, because those exist but you probably shouldn’t use them.
(Related reading: https://stackoverflow.com/questions/2243824/what-is-the-diff....)