Hacker News new | ask | show | jobs
by xamuel 4184 days ago
They don't even do One Thing Well. The is-upper-case example checks uppercaseness by converting the entire string to uppercase and checking whether the result equals the original. What if the string in question is "xxx...x" (lowercase x repeated a million times)?
2 comments

Doing "One thing well" can be defined in several things depending on what you consider of utmost importance for wellness.

I think that function does what it's supposed to "well" in the sense that 1. it works, 2. the code is clean and obvious and 3. it doesn't try to be clever and do "complex" things which can introduce bugs.

I'm guessing from your complaint that you think it doesn't do things "well" because you prefer code to computationally efficient over conceptually and declaratively clear?

You can argue that "But for -this- little thing I can afford to be a clever and throw the obvious-looking code out the window!", but then everyone else also gets to do the same judgement too.

And then suddenly you're all using "clever" code all over the place with new ingenious ways to break everywhere in your code-base. And just like clockwork, your application will start breaking and nobody will know why without spending hours, days or even weeks debugging.

Let's say I generally don't think computationally efficient code is worth that cost. I'll make exceptions for specific code-portions which needs to be fast, but for my bread and butter code? Make it plain and simple!

If I'm importing a module for is-upper-case, it had better be for a reason: that someone actually did something significant on that problem and I don't want to reinvent their work.

The module in question is nothing but a #define macro. Javascript lacks a preprocessor and this community's response is apparently to outsource #define macro's to a centralized server.

>And just like clockwork, your application will start breaking

The alternative is that just like clockwork, your application grinds to a crawl and practically freezes the browser. Because you outsourced every last thing to someone who doesn't care about performance. Sure, it's fine for the static-html-page-that-you're-doing-in-node-for-some-inexplicable-reason. Just hope you know what you're doing when you do something more complicated.

If I am going to add a dependency for some shit like this, it better at least be exceptionally well optimized and have no bugs.
That's a great point! Maybe you should log an issue or make a PR and fix it for everyone (except those who copied and pasted). This is exactly why it's a good thing for smaller modules that do one thing well, because when a tiny bug pops up everyone can automatically apply the patch.

I did do some tests a around this, but it showed nothing substantial. The comparison solution is much faster overall, the only point it falls down is with all lowercase strings where an early return would obviously be faster. Even a regexp was faster in some cases. It's highly subjective.