Skip to main content
added 196 characters in body
Source Link
Dave C
  • 7.9k
  • 18
  • 12

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

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

By the way, I'm not refering to one line code snippets; I'm referring to fully runnable example code (which is 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.

[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 actually referring to one or two line code snippets like I've shown here; I'm referring to otherwise fully complete functions or fully runnable example code (which, 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.

added 147 characters in body
Source Link
Dave C
  • 7.9k
  • 18
  • 12

[I'm the original commenter]

My opinion is that full example code should at minimum there should behave a comment of some sort. E

E.g. Instead of (Go example)

Instead of:

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

By the way, I'm not refering to one line code snippets; I'm referring to fully runnable example code (which is 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.

[I'm the original commenter]

My opinion is that at minimum there should be a comment of some sort. E.g. (Go example)

Instead of:

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

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.

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

By the way, I'm not refering to one line code snippets; I'm referring to fully runnable example code (which is 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.

added 232 characters in body
Source Link
Dave C
  • 7.9k
  • 18
  • 12

[I'm the original commenter]

My opinion is that at minimum there should be a comment of some sort. E.g. (Go example)

Instead of:

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

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.

[I'm the original commenter]

My opinion is that at minimum there should be a comment of some sort. E.g. (Go example)

Instead of:

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

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.

[I'm the original commenter]

My opinion is that at minimum there should be a comment of some sort. E.g. (Go example)

Instead of:

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

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.

Source Link
Dave C
  • 7.9k
  • 18
  • 12
Loading