Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Every time I hear about tings like left-pad and is_even, I have to wonder... Are JS developers ok? There seem to be a lot of packages for extremely trivial things that nonetheless gets huge amounts of downloads




Many of these issues stem from the fact that Javascript doesn't have anything like stdlib or equivalents. I'm willing to bet money that most people can't write a bug free left-pad in Javascript on the first try without looking stuff up. Reaching for a dependency can make a lot of sense in that context.

I'm not a JS developer, so maybe they'd do it differently, but I'd probably do a bounds check, returning early if the target length is less than the input length, then create a string of spaces that is (targetlength - inputlength) long, and return them concatenated. Quick google shows theres a string.repeat method so probably use that (does that not count as part of an stdlib?).

Also, I'd bet money that most people couldn't write most things bug free on the first try without looking stuff up unless it's trivial


That's how I imagine most people would start, but unfortunately that will break on anything beyond basic ascii strings. Arabic, Hindi, Vietnamese, etc use diacritics, combining characters and so on, and this isn't even getting into the mess of emojis and their modifiers.


It would, I was not familiar with the specific package, more so commenting on the problem at large. Even coding problems that sounds fairly straightforward can be a source of many dragons if you don't have good tools to solve them.

How often would it matter? I can certainly write code that would cover all use case I was expecting and case bash all the scenarios. I’m sure I’d fall victim to edge cases.

If this was such a common use case that it warranted being in some sort of stdlib, then make a standard lib and make sure it can’t be deleted.


It’s funny because the article raises those issues as examples of code reuse being dogmatic. Not as a problem with the eco system.

We’re stuck with it now. We should be engineering front end with the assumption that it will break or get compromised.


We’re generally fine and well paid. :) Frontend tooling churn is tiresome but the upside is that there is a lot of great tooling that more than makes up for any language deficiencies.

is-even was most likely made as a joke

Sure, but it has 170k weekly downloads, and 61 packages depend on it, not all of which seem to be jokes (eg markdown-list and cli-barchart).



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: