Google's Go & Exceptions
John D
jdean at googling.com
Fri Jan 29 22:45:49 PST 2010
"Walter Bright" <newshound1 at digitalmars.com> wrote in message
news:hjni3o$r26$1 at digitalmars.com...
> Andrei Alexandrescu wrote:
>> Walter Bright wrote:
>>> bearophile wrote:
>>>> In GCC there is also the "warn_unused_result" function attribute
>>>> that
>>>> raises a compile time warning if you don't use the return value of a
>>>> function:
>>>
>>> That may wind up suffering similar problems as checked exceptions
>>> do - just do a quick and dirty assign the return value to a hastily
>>> declared temp and ignore it, meaning to fix it later.
>>>
>>> Of course, it doesn't actually get fixed later. Even worse, during
>>> code reviews, it will look like the code is paying attention to the
>>> error code, but it won't be.
>>
>> I'd think in a code review a variable assigned and subsequently never
>> used is bound to raise a red flag.
>
> I agree, if it was noticed. For me,
>
> int result = foo();
>
> in the code implies that 'result' is later used. I'd have to search to
> see if it wasn't, which is harder than noticing that:
>
> foo();
>
> ignores the result.
>
>
> This goes back to my theory that a feature that encourages the
> programmer to insert misleading dead code to shut the compiler up is a
> misfeature.
A programmer who does the above is not a good programmer. That said, a
compiler that doesn't warn that variables or arguments have gone unused
in a function is not a good compiler. That said, a language that doesn't
enforce return val checking is not a good programming language.
More information about the Digitalmars-d
mailing list