News for hackers. Stuff that matters.
Re:The most copied StackOverflow snippet of all time is flawed by drunkendog on Wednesday September 27, 2023 @10:29AM (#37675169)
Replacing 4 line solutions with extensive libraries is what caused left-pad.
Re:The most copied StackOverflow snippet of all time is flawed by LoganDark on Wednesday September 27, 2023 @10:40AM (#37675330)
No. left-pad was placing a 4-line solution in a library. prettysize is well deserving of library status.
Re:The most copied StackOverflow snippet of all time is flawed by eviks on Wednesday September 27, 2023 @10:40AM (#37675331)
What caused left-pad is the the ability to delete published code
Re:The most copied StackOverflow snippet of all time is flawed by Cthulhu_ on Wednesday September 27, 2023 @10:56AM (#37675557)
Yeah, copying an incorrect answer from SO thousands of times is much better!

(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)

Re:The most copied StackOverflow snippet of all time is flawed by Analemma_ on Wednesday September 27, 2023 @11:05AM (#37675685)
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.
Re:The most copied StackOverflow snippet of all time is flawed by riversflow on Wednesday September 27, 2023 @11:28AM (#37676079)
> “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.

Re:The most copied StackOverflow snippet of all time is flawed by mikepurvis on Wednesday September 27, 2023 @11:51AM (#37676516)
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.

Re:The most copied StackOverflow snippet of all time is flawed by paholg on Wednesday September 27, 2023 @07:37PM (#37683043)
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
Re:The most copied StackOverflow snippet of all time is flawed by delta_p_delta_x on Thursday September 28, 2023 @03:00AM (#37686277)
You should see the implementation of `std::midpoint`[1].

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...