The snippet from S/O may be four lines but these are much more extensive, come with tests, output formatting options, conversion between sizes, and more.
The snippet from S/O may be four lines but these are much more extensive, come with tests, output formatting options, conversion between sizes, and more.
(The subject at hand isn't whether libraries are good or not, it's whether copying something off the internet is. In the post, it turns out it isn't. If it was a library, the author could have fixed and updated the library, and the issue would be fixed for everyone that uses it. left-pad isn't an issue with libraries per se, it's an issue with library management)
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.
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.
Accounting for correctness even in edge-cases is what large libraries do better than throwaway bits of code.
[1]: https://github.com/microsoft/STL/blob/6735beb0c2260e325c3a4c...