4 ms·
A real problem is when something like this occurs x, err := thisFuncFails(); // some other lines of code, but err is not checked x.callMethod(); //
by nemothekid 4y ago
A real problem is when something like this occurs
x, err := thisFuncFails();
// some other lines of code, but err is not checked
x.callMethod(); // this crashes at runtime
unless you explicitly ignore `err`, the compiler shouldn't allow you to use `x` without checking err. In Rust/Zig this is accomplished with the union types, which doesn't allow to use `x` until you have checked it's not an error. This is also very useful for Option types; and I wish it was in Go since the beginning as having `nil` in the language is a huge mistake.
- Macha 4y agoThe problem is worst with procedural functions os.Mkdir("foo") looks pretty innocent but with no return value to use, the compiler is no help in reminding you this is a fallible function
- nathants 4y agoadd errcheck and ineffassign to your build script. the compiler should really do this itself.