I think it'd improve safety and make writing reliable programs easier
to just apply this to all functions returning a value. This would make
it less nice for people throwing together quick scripts, of course...
Perhaps a compiler flag?
Which is hideous.
--
matt kane's brain
http://hydrogenproject.com
capoeira in boston http://capoeirageraisboston.com
aim -> mkbatwerk ; skype/y! -> mkb218 ; gtalk -> mkb.dirtyorg
Another example: you almost never care about the return values of fmt.Println.
I don't think the compiler is the place for this.
It would be fairly easy to create a simple program that could find
place in code where return values were ignored.
Perhaps it could go in govet.
> This feature would close a hole in Go's style of dealing with errors
> via return value. With more than one return value (e.g. one "normal"
> return value and one error object), it's impossible to ignore the
> error while still extracting the desired result. But with functions
> that return only an error value, e.g.
>
> func (req *Request) Write(w io.Writer) os.Error
>
> it's easy (and probably common) to drop the error value on the floor.
>
> Of course, we can do better than gcc's syntax. I was thinking of
> something like
>
> func (req *Request) Write(w io.Writer) os.Error!
>
> This requires no new keywords and, IMHO, does a good job of conveying
> the intent.
>
> Callers that insist on ignoring the return value can always write
>
> _ = req.Write(w)
>
--
=====================
http://jessta.id.au
Can we at least call it goverity? :)
I don't think the compiler is the place for this.
It would be fairly easy to create a simple program that could find
place in code where return values were ignored.
Perhaps it could go in govet.
> I think Kyle already provided the answer to this: have a file of known exceptions
The problem with this is that it leaves control entirely up to the user, who might not be the best one to decide. Maybe there should be a way to temporarily silence a warning, but overall, I think it's better to be able to disable that and still have sensible warnings.
> I disagree, it leaves control up to the developers. The first time you run it you would see a large number of "errors". You then determine which ones are harmless and fix the other ones. Now in the future as you modify the code you will no longer hear about the the harmless ones but any new ones will generate warnings for you to look at.
You can't have a machine global list. That will just accumulate ignores to the point of meaninglessness (unless it is locked, standard, and enforced by the company/project). So, either each package comes with good defaults, which you can revert to easily, or you have to go from scratch for each package, and manually go through and reassess every decision as situations change. The latter is simply unmanageable, since you can't separate the important decisions from the noise.
> The lists certainly go hand in hand with the source files. This is something that should be decided on a project by project basis, not thrust upon an entire community.
>
> I was viewing this as how can a team write good code, validate "risky" constructs, and catch errors of regression. So yes, I believe it should be enforced at the project level. From your comments perhaps you, as a package developer, want to force certain practices upon developers who use your package (which would explain why you used the term "users").
Not "force", just "encourage" :). The package provider is in a better place to know if ignoring the return values is safe in general. The package user is in a better place to know if ignoring the return values is safe for their use case, but would have to really think about it before going against the suggested use to make sure it's actually sufficiently safe for them. I think you need a bit of both to prevent the tool becoming useless in the face of noise, from either direction.
> If that is your goal then we probably will agree to disagree :-)
But that's no fun! :D
Not "force", just "encourage" :).