I've never seen any code that handled err -- I don't mean ignoring it with _, I mean not even acknowledging its existence -- without the compiler saying anything.
I've never seen any code that handled err -- I don't mean ignoring it with _, I mean not even acknowledging its existence -- without the compiler saying anything.
People usually don't check the return code of fmt.Printf because they simply don't care. Most of the time, you're just logging to a terminal, which basically never fails. And if logging did fail, you wouldn't want to abort the program because of it.
The only time you might want to check the return value of printf is if you're writing a simple utility designed to transform something passed on stdin to something on stdout.
yourprogram | head -100For fun, I wrote three programs that just print 1 2 3 ... to stdout forever, in python, go, and plain c. None do any error checking.
Here's the results:
$ py printcount.py | head -10
1
2
3
4
5
6
7
8
9
10
Traceback (most recent call last):
File "printcount.py", line 3, in <module>
print i
IOError: [Errno 32] Broken pipe
$ go run printcount.go | head -10
1
2
3
4
5
6
7
8
9
10
signal: broken pipe
$ ./printcount | head -10
1
2
3
4
5
6
7
8
9
10
$ pgrep printcount
$
Interestingly enough, only plain old C actually did what I wanted here. In Go and Python, we'd have to do a little work to not print the annoying error. But I don't think we want to check return codes from print in any of the languages.