init/assignment to self in (…) (was: [SVN] r3154 (Objective-C))

Allan Odgaard throw-away-1 at macromates.com
Fri May 12 12:42:36 UTC 2006


On 1/5/2006, at 16:13, Chris Thomas wrote:

> There's no impact on the generated binary, but there's a negative  
> impact on source code maintenance.
>
> In C, it's easy to inadvertently type "a = b" (assignment) where  
> you intended "a == b" (equality). I've occasionally found such bugs  
> in large code bases. The compiler can find this error for you by  
> issuing warnings for assignments in if-statements. In GCC, this is  
> controlled by -Wparenthesis.
>
> If nothing in the standard snippets should cause a warning, the  
> assignment should be outside of the if statement.

Xcode’s default project use -Wmost instead of -Wall, where the former  
is (iirc) a switch Apple added to GCC, and it does not warn with  
assignments in parenthesis (unlike -Wall).

I won’t speculate about whether this was added for pragmatic reasons  
or Apple’s blessing of assignment inside parenthesis, but it does  
mean that the snippet works with Xcode generated projects and their  
default warning level.

But it’s a tough one: I do a lot of parenthesis assignment, and can’t  
stand the lack of this in Java, but I also see the value of turning  
on all warnings.




More information about the textmate-dev mailing list