4 ms·
So basically these libraries are like Python's itertools for JS? Except they made a silly/arrogant choice of using a single character for the library name.
by csense 11y ago
So basically these libraries are like Python's itertools for JS? Except they made a silly/arrogant choice of using a single character for the library name.
- robertfw 11y agoThe reason for the single character library name is that by convention, the library is imported into a variable named "_". This reduces code noise and amount of typing if you are using these functions frequently I'm not sure how that is silly or arrogant
- dopamean 11y agoJust someone who doesn't write much JS.
- csense 11y agoImagine if every library you used named itself with a single character. Does your language have more than 27 libraries available? Then sorry, some of their choices of letter will overlap and those libraries will conflict, perhaps requiring you to manually edit the distribution source or build scripts. Do you ever want to create a project that has more than 27 transitive dependencies? Yeah, good luck with that. Found a code snippet online and want to figure out what library it's invoking? Hint: Google is probably going to be useless when searching for a single-letter name. The problems with using single-character names for libraries are so self-evident, I'm not quite sure how to respond to someone who doesn't see it.
- Macha 11y agoIt's like Python's itertools if: * list and dict were lacking vital methods like list.remove() and dict.__len__() * dicts weren't really a real thing (real ones coming in ES6 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... ), but it was easy to add random properties to arbitrary objects while accessing a missing one simply returned None, and so these were used instead * Which leads to for x in dct being subtly broken in certain use cases unless you understand the above and how it interacts with prototypes * So loads of utility functions were added to deal with the above facts, plus the kind of useful tools you would find in Python's functools and itertools and a large number of other utility functions while they're at it. (EDIT: One of these days I will remember HN doesn't use Markdown, but not today)
- csense 11y agoSo basically the JS built-in container and prototype semantics are totally stupid, broken and confusing. I already knew this. Apparently underscore is a community-driven "stdlib" that implements more functionality and saner container classes, and has more freedom to evolve since it's not part of the core JS language. And the justification for using a single-character name is that it's basically a de facto part of the stdlib?