Comment by Analemma_
2 years ago
I understand where you're coming from here, but the whole point of this article is at the 4-line solution is wrong (and the author specifically mentioned that every other answer on the stack overflow post was wrong in the same way as well). "Seemingly-simple problem where every naïve solution contains a subtle bug" is exactly the right use case for a well-designed library method.
> “It’s wrong”
But in a completely benign way. I question why a few edge cases of writing 1000kb instead of 1Mb—so not even a misrepresentation—would ever be worth the code bloat. This is about making stuff slightly more convenient to read.
I agree with you— that was a lot of drumming for what turned out to be kind of a nothingburger as far as the "bug".
At the same time, putting this kind of thing in a library (or even a language's stdlib) is worthwhile for exactly this kind of reason— it allows devs to confidently reach for code that other smart people have really agonized over and which definitely covers the corner cases, similar to other common utilities such as sort methods.
One example: I display available memory in my status bar, which expects strings to be a constant width. If it displayed 1000kb, it would cause alignment issues and annoy the heck out of me