News for hackers. Stuff that matters.
Re:The most copied StackOverflow snippet of all time is flaw... by beermonster on Wednesday June 16, 2021 @06:24PM (#27534155)
> I wrote almost a decade ago was found to be the most copied snippet on Stack Overflow. Ironically it happens to be buggy.

I don’t find it ironic, I find it quite normal that even small snippets of code contains bugs (given the daily review requests I receive).

I think when copying code literally from StackOverflow what’s more important is understanding what the code does, and why , rather than copying it ad-verbatim by copy & pasting it into your production code.

I also often find on StackExchange et al that quite often the most upvoted is the one that ‘fixes it’ for ‘most people’ yet the correct answer is down at number 3 or 4. Again, understanding the answer and why it applies, helps give you the context to understand if this is actually the solution to your problem or just treats the symptom.

Re:The most copied StackOverflow snippet of all time is flaw... by mninm on Wednesday June 16, 2021 @07:31PM (#27534678)
What I realized years ago is that the upvote on Stack Overflow don't mean "I tried this and it works for me" or "I'm an expert and this is the answer". No, the upvotes on Stack Overflow are along the line of the upvotes/likes one would find on Reddit or HN. More like "you sound confident" or "I was looking for this but I haven't tried it yet"
Re:The most copied StackOverflow snippet of all time is flaw... by MaxBarraclough on Wednesday June 16, 2021 @07:47PM (#27534774)
> No, the upvotes on Stack Overflow are along the line of the upvotes/likes one would find on Reddit or HN. More like "you sound confident"

I think you're right that online scoring systems tend to incentivise false confidence. This happens with blog posts too, where a student of some topic writes a confident and subtly incorrect blog post, and it then ends up on the HN front-page. Only someone with a relatively deep knowledge of the topic can then call out the errors. Ideally it should always be made clear upfront that the author is new to the material.

Somewhat related: Stack Overflow's unfortunate norm of calling out mistakes in answers in a way that goes beyond confidence and strays into condescension and borderline hostility. For a lot of people it seems it's not enough to be seen to be right, they also feel the need to paint someone else as clueless, while just about passing as acceptably polite by keeping the aggression passive. If challenged, they'll brush it off as 'directness'.

Re:The most copied StackOverflow snippet of all time is flaw... by kenniskrag on Wednesday June 16, 2021 @08:13PM (#27534923)
Also to create a democracy.

> Our sites are all intended to be a sort of representative democracy. Moderator elections are an important part of that plan, but voting on questions and answers is the primary mechanism through which the community governs the site on a day to day basis.

https://stackoverflow.com/help/why-vote

Re:The most copied StackOverflow snippet of all time is flaw... by bombcar on Wednesday June 16, 2021 @09:53PM (#27535466)
And it can fall to all the errors and issues of democracy too - especially the “pseudo-expert” one. At least you can leave a comment on the answer if there’s an issue.
Re:The most copied StackOverflow snippet of all time is flaw... by fouc on Wednesday June 16, 2021 @09:04PM (#27535224)
experts can edit the stackoverflow answers (assuming their stackoverflow rating is high enough)
Re:The most copied StackOverflow snippet of all time is flaw... by sixothree on Thursday June 17, 2021 @11:55AM (#27541018)
The number of times I've seen the only correct answer being a terse explanation with a short code snippet and having zero upvotes astounds me.

They may not have been the attention seekers like other posters. But they provided exactly what was asked for. And when I come across their post years later I upvote.

Re:The most copied StackOverflow snippet of all time is flaw... by ImprovedSilence on Wednesday June 16, 2021 @10:09PM (#27535536)
> More like "you sound confident"

Meh, I'm usually there looking for how to do something, and if a response helps me do whatever I was looking to acomplish, or at least on the right track, it was helpful and worth an upvote. I've never upvoted just because someone sounded confident.... at least not on SO.

Re:The most copied StackOverflow snippet of all time is flaw... by keanebean86 on Wednesday June 16, 2021 @11:19PM (#27535834)
There's also the possibility that the answer was correct when written. Especially with web stuff a year old answer could be completely wrong now.
Re:The most copied StackOverflow snippet of all time is flaw... by Nowado on Wednesday June 16, 2021 @07:52PM (#27534802)
It's a user experience issue and it's hard to solve. You can't possibly expect people to come back to one of their SO tabs AFTER they get code to work.
Re:The most copied StackOverflow snippet of all time is flaw... by nomadiccoder on Wednesday June 16, 2021 @10:06PM (#27535521)
Why not? I dont upvote an answer unless it works...
Re:The most copied StackOverflow snippet of all time is flaw... by luckman212 on Wednesday June 16, 2021 @10:54PM (#27535724)
I think it was sarcasm... just missing the /s
Re:The most copied StackOverflow snippet of all time is flaw... by megalodon on Wednesday June 16, 2021 @06:47PM (#27534343)
One of the best tips I have gotten from the internet is to never copy and paste code you have not written yourself. Even rewriting it verbatim makes you think about what it is you are actually copying.

It's a pretty neat rule to have in mind.

Re:The most copied StackOverflow snippet of all time is flaw... by jozvolskyef on Wednesday June 16, 2021 @07:28PM (#27534662)
Ladislav Vagner, a legendary programming tutor at FIT CTU, is a known proponent of being extremely cautious when copying code, even your own. He gives programming proseminars where students guide him as he codes the solution to some problem, e.g. mathjax-like typesetting in C++. It is a common theme in the proseminars that a bug is introduced by copying code. Probably on purpose, like many of the other bugs that students are supposed to point out.
Re:The most copied StackOverflow snippet of all time is flaw... by tshaddox on Wednesday June 16, 2021 @07:37PM (#27534718)
I think that’s true if you’re trying to learn a new tool or technology. You probably won’t learn as much following the Rails or Django tutorials if you’re just pasting all the code. But if you’re just looking for some esoteric workaround for some very specific tool and use case, I think it’s fine to paste. And the latter makes up the overwhelming majority of my Stack Overflow visits.
Re:The most copied StackOverflow snippet of all time is flaw... by dcow on Wednesday June 16, 2021 @07:24PM (#27534635)
It's also good legal advice. It's now legally possible for you to copy and paste code directly from stack overflow because they made an effort to assert a compatible license over works published on their site. However, the same can't be said for most other code snippets flying around out there.
Re:The most copied StackOverflow snippet of all time is flaw... by distances on Thursday June 17, 2021 @02:56AM (#27536854)
Good point in case: license of the code in this exact article is very likely incompatible with your production code.
Re:The most copied StackOverflow snippet of all time is flaw... by corobo on Wednesday June 16, 2021 @07:16PM (#27534586)
When you get into this habit it also makes it easier to translate solutions from other languages too
Re:The most copied StackOverflow snippet of all time is flaw... by specialist on Wednesday June 16, 2021 @10:52PM (#27535719)
Yes, and:

I didn't really grok Test Driven Development until I worked thru the book, line-by-line, experiencing the workflow.

Knowledge vs experience.

Re:The most copied StackOverflow snippet of all time is flaw... by ImprovedSilence on Wednesday June 16, 2021 @10:10PM (#27535540)
Agreed. Otherwise it's not uncommon for me to not know what 80% of the code is even capable of...
Re:The most copied StackOverflow snippet of all time is flaw... by OJFord on Wednesday June 16, 2021 @07:11PM (#27534545)
> I also often find on StackExchange et al that quite often the most upvoted is the one that ‘fixes it’ for ‘most people’

And also first, or at least early, and subject to a reinforcing cycle of 'sufficiently good' or 'fixed it enough' that it achieves stratospherically more votes than an 'even more good' or 'fixes it properly' answer that came in too late for the same traction.

Re:The most copied StackOverflow snippet of all time is flaw... by bigiain on Wednesday June 16, 2021 @09:12PM (#27535267)
> also first, or at least early, and subject to a reinforcing cycle of 'sufficiently good' or 'fixed it enough'

So exactly the solution most project managers are after? /s

Re:The most copied StackOverflow snippet of all time is flaw... by OJFord on Thursday June 17, 2021 @04:12AM (#27537269)
Ha, well even if there's an argument for that, it quite often leads to (and is even more reinforced by in terms of votes) the original asker 'accepting' the solution; then the answer that 'fixed it for them, first' is forever ranked highest, even if it rarely works for others and something else is more up-voted.
Re:The most copied StackOverflow snippet of all time is flaw... by cratermoon on Wednesday June 16, 2021 @09:11PM (#27535259)
Remember the npm left-pad disaster? That code had bugs in it. See slide 44: https://www.slideshare.net/Kevlin/good-code-73714882
Re:The most copied StackOverflow snippet of all time is flaw... by sixothree on Thursday June 17, 2021 @11:53AM (#27540989)
This works better when the problem does not 100% match the issue you are tackling. It makes you think about how you can reshape what you found into something useful.