[I'm the original commenter]
My opinion is that full example code should at minimum have a comment of some sort.
E.g. Instead of (Go example):
value, _ := Func1()
Func2(value)
do:
value, err := someFunc()
// check err!!
err = Func2(value)
(in particular, if the reader doesn't go to the documentation, like they should, they may not even realize Func2
returns an error). Also note, that at least for Go, just including err
might be sufficient since an unreferenced variable is a compiler error, so it will be clear the code is incomplete. (E.g. how hard is it to say v, err := …
instead of v, _ := …
??)
By the way, I'm not referingactually referring to one or two line code snippets;snippets like I've shown here; I'm referring to otherwise fully complete functions or fully runnable example code (which is, along with a play.golang.org link, appears to be the norm for Go answers here).
Although it's true that some people will just do foolish things and that can't be prevented; we can at least make it a little harder for someone that just doesn't know any better to start getting into bad habits.
The issue is that as much as we can blame the fools that cut-n-paste bad/incomplete examples into their own code, this happens. And then some other SO user has to waste time answering a question by someone that is ignoring errors.