4 ms·
It may be logical but: - I know all that, have been programming for 15 years, yet I still would have done the mistake. - Simple unit tests may very well not c
by sametmax 7y ago
It may be logical but:
- I know all that, have been programming for 15 years, yet I still would have done the mistake.
- Simple unit tests may very well not catch this bug the first time.
- The language design allows your brain to ignore the index parameter because JS accepts superfluous parameters, which is a terrible decision.
- map() is a mapping primitive. It's supposed to adapt a type to another type so that you can pass it to a monoid. JS breaks this convention.
- Even traditionally not functional languages know better than that and separate iteration from indexing. E.G: python map() just maps, and if you want numbering, you use explicitly enumerate(). Ruby has each() and each_with_index(), etc.
Just another of the numerous sucky things in JS. They are not big, but they accumulate very quickly and make it one of the worse language existing. Certainly the worst of all modern stack languages. It's a shame it has a monopoly on the most awesome platform in the world: the web.
In fact, it's such a big problem the most popular JS projects are all things to avoid coding in JS or workaround JS deficiencies: typescript, coffeescript, jsx, babel, webpack, lowdash ...
- megous 7y ago> - The language design allows your brain to ignore the index parameter because JS accepts superfluous parameters, which is a terrible decision. Without that we would not be able to have variable length argument lists in the past.
- sametmax 7y agoYes, but again that's the consequence of another bad design: not including spread or another metaprogramming system for this. And not having default values either. Spread has existed in Python forever under the name of "splat operator", default values as well. Same with ruby. That what I meant when I said "they accumulate". A bad design decision not only affect the user cognitive load and productivity, but it also cascades to the rest of the language and shapes it.
- o_nate 7y agoWhenever I learn about another of these Javascript foot-guns, I come away with a greater sense of awe at the relentless good sense that went into the design of Python. Not sure if it's a kind of super-human Dutch ability to foresee ramifications of design decisions, or if it's just that Python developed organically over a period of time with healthy feedback from smart and invested users.
- sametmax 7y agoIt's also about the ability to say "fuck off". People came at Guido relentlessly for adding new features, debating his decisions, trying to change the philosophy and aesthetic of the language. The guy stood up to them for 20 years, staying polite but resolute at doing things his, at the time controversial, way. To me, that's even more impressive than being a good language designer.
- jacobolus 7y ago> in Python forever under the name of "splat operator" The name “splat” is not commonly used in Python. That name comes from Ruby (or Perl?). In Python it is usually called “star” or similar.
- sametmax 7y agoBoth are used. Here you can see Steven D'Aprano, one of the dev of the Python stdlib, naming it "splat": https://mail.python.org/archives/list/python-ideas@python.org/message/4IYAQPAYBQ4QGIXAJ6BSGM6OFR6IMEKT/ https://mail.python.org/archives/list/python-ideas@python.or... I use "splat" all the time myself. On the other hand, itertools.starmap() is named this way because it does: def starmap(func, iterable): for e in iterable: yield func(*iterable) Things rarely have one name in computing. Hell I call curly brackets "mustaches" all the time. It's as hard as cache invalidation apparently.
- jacobolus 7y agoThat’s a mailing list email from 2016, and is a joke about bunch of silly non-standard names for punctuation (e.g. “bang”, “wack”, and “twiddle”). Obviously occasional people are going to pick up terminology from other communities, and the name “splat” has been gaining popularity recently (I had literally never heard that term before a few years ago, and have been writing Python code since 2002). I occasionally hear British expats in the USA calling elevators “lifts” or baby carriages “prams” or lines of people “queues”. Doesn’t mean those have been common American terms. This was certainly not called the “splat operator” “forever” as claimed in the previous comment. > I call curly brackets "mustaches" all the time I have never heard anyone call these “mustaches”. The common terms are “curly brackets” and “braces”. Nobody is going to have any idea what you are talking about.
- sametmax 7y agoThe most famous JS template engine of the early 2000 used to be literally called "mustache" because of it: https://mustache.github.io/ https://mustache.github.io/
- jacobolus 7y ago> I know all that, have been programming for 15 years, yet I still would have done the mistake. I have not done it with parseInt per se, but I have made this precise mistake at least twice with passing a function `f` with an optional second argument in `some_array.map(f)`, and it took a while to figure out what was happening each time. Now that Javascript has proper iterables and iterators and generators, I have been enjoying using versions of `map` and `spreadmap` which take in a callback function and iterables and produce an iterator. Then I can explicitly use `enumerate` if I want it. https://observablehq.com/@jrus/itertools#map https://observablehq.com/@jrus/itertools#map
- Oreb 7y agoAs a (mostly) outsider, I’ve never understood why JavaScript is so popular in web dev circles. There are so many awesome compile-to-JS languages these days (ClojureScript, PureScript, Elm, ReasonML, Scala.js, etc). What makes people want to use JavaScript instead?
- RussianCow 7y agoAny time you use anything non-native, you add layers of indirection and potentially lots of impedance mismatch between languages/runtimes. For instance, I know all of the ones you mentioned would be non-starters at my current job because it means we would have to wrap all of our JS libraries/APIs in the language of choice, which is a non-trivial amount of work. Plus, debugging becomes more challenging as you're basically having to do it at two levels simultaneously. Even with all of JavaScript's deficiencies, it's still far easier to just deal with them than to switch languages entirely.
- lagg 7y agoI too remember the time when we didn't assume there'd be a Makefile-ish system that has to bundle everything, compile the sass, pull bootstrap, etc. Then there's the map files for debugging that will generate cleanly every now and then. I've adapted but these strange abstraction languages are still where I'm drawing the line. At a certain point it's like, are you choosing the language for the project or is it the other way around. Hah, I just remembered Vala. Edit: Also this thread and the internet in general make me feel bad for liking javascript. It has issues with the global namespace being all wrecked when used for DOM, but the language in and of itself I just find cool for the same reason I find JSON and the way lisp treats objects/data/code cool. So many playa hataz :(
- wutbrodo 7y agoIt's permissiveness means you can hit the ground running more easily writing shitty but functional code, and web dev has long been the gateway for new entrants to engineering. People start programming, learn shitty habits from a shitty language ,and then the religious affinity for programming languages that many have starts to kick in. This obviously doesn't explain every Javascript fan, but the tendency is strong enough to shift the dynamics of the community. I can't say I relate to the religious fervor with which people defend programming languages. C++ is probably my favorite language to work in, but I absolutely understand where the hatred for it comes from. I readily admit that it's grotesque in many ways and my preference is likely for lack of sustained exposure to certain other modern languages.
- Shish2k 7y ago> Certainly the worst of all modern stack languages So have you not used PHP, or are you counting it as not-modern? :P
- sametmax 7y agoI've started my career as a PHP dev. Even if you consider them equally bad, at least PHP has a stdlib and no prototypal inheritance.