4 ms·
Why would it drive you crazy? This is an example of someone not even knowing how the map function works.
by notus 7y ago
Why would it drive you crazy? This is an example of someone not even knowing how the map function works.
- nilkn 7y agoI would certainly consider this a "gotcha" because it's unexpected that map both deviates from the norm and the language makes it so easy to misuse and hide that misuse. This reminds me of "array set" in Tcl (a language many probably haven't used in a long time -- or ever). Unlike the normal "set" command in Tcl, which overwrites the full value of the variable, "array set" is actually a merge operation -- it merges in new keys and doesn't get rid of anything. I've seen experienced programmers use "array set" in a loop, leading to awful bugs. This too could be dismissed by saying that they "don't even know how array set works," but actually I place the blame on the language for making it so easy to misuse.
- maxxxxx 7y agoOnce you work with several languages it’s really hard to keep track of all this stuff. I never know what exactly evaluates to true vs false in PHP or JavaScript for example. Add to that sloppy programmers on your team who don't check their assumptions it’s really easy to have a ton of subtle bugs in your code.
- fieryscribe 7y ago> I never know what exactly evaluates to true vs false in PHP or JavaScript for example. You don't have to know if you don't use implicit type-casting. Make it explicit and you won't really have to worry about it. "Explicit is better than implicit" is part of the Zen of Python for a very good reason.
- maxxxxx 7y ago"You don't have to know if you don't use implicit type-casting. Make it explicit and you won't really have to worry about it. " Correct. Unfortunately a lot of people use implicit casting a lot and have no idea that that's what they are doing.
- tntn 7y ago> not even knowing how JavaScript implements map in a nonstandard way that breaks simple examples FTFY. I know exactly how map works: https://en.m.wikipedia.org/wiki/Map_(higher-order_function) https://en.m.wikipedia.org/wiki/Map_(higher-order_function) This is map: > a higher-order function that applies a given function to each element of a functor, e.g. a list, returning a list of results in the same order. Since that is not what Array.prototype.map does, it is not map, it is some similar thing that is misnamed as map. If I wanted the index and the array as arguments, I would ask for them.