3 ms·
Linters are available to catch you before you compile - with Go Generally speaking there has to be a mechanism for optional handling of return values, in Go yo
by awesome_dude 5mo ago
Linters are available to catch you before you compile - with Go
Generally speaking there has to be a mechanism for optional handling of return values, in Go you can ignore everything (ew), you can use placeholders `_`, or you can explicitly handle things - my preference.
If you say "Well in C you have to handle the returns - I am not across C enough to comment, but I will ask you - Does C actually force you, or does it allow you to say "ok I will put some variables in to catch the returns, but I will never actually use those variables" - because that's very much the same as Go with the placeholder approach
edit: I am told the following is possible in C
trySomething(); // Assumes that the author of trySomething has not annotated the function as a `nodiscard`
(void)trySomething(); // Casts the return(s) to void, telling the compiler to ignore the non-handling
int dummy = trySomething(); // assign to a variable that's never used again
I welcome correction
- ventana 5mo agoC, as a language, cannot bother less about you using or not using the return values, checking them, discarding them, or using them to index an array without any bounds checking. Various linters and compilers may have their opinions, expressed as warnings, but at the end of the day it's completely up to you as a developer.
- awesome_dude 5mo agoYeah - I assumed so - which makes the GP post... bizarre
- LtWorf 5mo agoSame as in go, a language designed several decades later.
- ventana 5mo agoWhich is probably not really surprising, if we consider who were the original designers of Golang!
- awesome_dude 5mo agoFunny - you said Go was worse - now you're saying Go's the same...
- LtWorf 5mo agoIt is worse, gcc has the warnings at least, go does not. You need a 3rd party linter.
- awesome_dude 5mo agoOne compiler (gcc) - and it doesn't do it by default Go has go vet - baked in and runs by default I tire of your bad faith ignorance.