Re: Unnecessary Boolean Warning

2011-08-04 Thread Boyd Collier
At the risk of offending contributors to this list, whose knowledge and 
helpfulness I greatly respect, may I suggest that this thread has gone on long 
enough and that competing opinions on this topic would be better aired on some 
other list?

Boyd___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-04 Thread Sander Stoks
>> One important difference for instance is that if you write if (a() &
>> b()), both a() and b() will always be executed, while if you write if
>> (a() && b()), b() will be executed only if a() is true.
>
>
> The C language doesn't make any guarantees about that. While this
> optimisation is to be expected, the order of execution (left to right)
> and the optimisation (b not executed) is implementation dependent.
>
> This is a classic question for coding job interviews.

As has been pointed out, it most certainly does.  This is important
because it allows you to write stuff like

if (index < maxIndex && isValid(array[index]))
   ...

In languages which don't guarantee short-circuiting, the array could be
indexed out-of-bounds.

On a related note, somebody said he would be less confused if C didn't
have "two different kind of booleans".  In fact, it has none at all.  It
is part of the idiom that you should read "if(a)" as "if a is non-zero"
and not as "if a is true".

Regards,
Sander


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread Andy Lee
On Aug 3, 2011, at 11:20 PM, Graham Cox wrote:
> On 04/08/2011, at 1:17 PM, Preston Sumner wrote:
> 
>> I find short-circuit evaluation easier to read and much more concise, and, 
>> of course, it's always nice to avoid unnecessary levels of nesting.
> 
> 
> I wouldn't necessarily disagree, but companies often have their own coding 
> standards that forbid that sort of thing.

I guess I wouldn't protest either way, especially since "doThis && doThat" is a 
common idiom at the command line.

--Andy


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread Graham Cox

On 04/08/2011, at 1:17 PM, Preston Sumner wrote:

> I find short-circuit evaluation easier to read and much more concise, and, of 
> course, it's always nice to avoid unnecessary levels of nesting.


I wouldn't necessarily disagree, but companies often have their own coding 
standards that forbid that sort of thing.

--Graham


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread Preston Sumner

On Aug 3, 2011, at 8:10 PM, Andy Lee wrote:

> On Aug 3, 2011, at 9:51 PM, Graham Cox wrote:
>> I think the point they wanted to get across was that they didn't want to see 
>> code like this:
>> 
>> if( someFunction() && someOtherFunction()){ ... }
>> 
>> instead of:
>> 
>> if( someFunction())
>> {
>>   if( someOtherFunction())
>>   {
>>   
>>   }
>> }
> 
> 
> This I agree with. I "know"[1] about the short-circuiting behavior of && and 
> still I'd prefer the conditional flow be super-clear rather than have to 
> think about operator rules even a tiny bit. But now we're back where we 
> started.

I find short-circuit evaluation easier to read and much more concise, and, of 
course, it's always nice to avoid unnecessary levels of nesting.

Preston___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread Andy Lee
On Aug 3, 2011, at 9:51 PM, Graham Cox wrote:
> I think the point they wanted to get across was that they didn't want to see 
> code like this:
> 
> if( someFunction() && someOtherFunction()){ ... }
> 
> instead of:
> 
> if( someFunction())
> {
>if( someOtherFunction())
>{
>
>}
> }


This I agree with. I "know"[1] about the short-circuiting behavior of && and 
still I'd prefer the conditional flow be super-clear rather than have to think 
about operator rules even a tiny bit. But now we're back where we started.

--Andy

[1] Bearing in mind that what we "know" sometimes isn't so. :)

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread Graham Cox

On 04/08/2011, at 11:36 AM, glenn andreas wrote:

> More likely the somebody that interviewed you didn't have it correct in the 
> first place, scarring you for life...


Well, that part's true :)

I seem to recall I failed that question, the only one I did. So I got the 
lecture and never questioned it. I did get that job anyway, though in hindsight 
I'd rather I hadn't, but that's another story...

I think the point they wanted to get across was that they didn't want to see 
code like this:

if( someFunction() && someOtherFunction()){ ... }

instead of:

if( someFunction())
{
if( someOtherFunction())
{

}
}


where (they claimed) in the first case someOtherFunction() may or may not run 
depending on compiler implementation, and not dependent on the result of 
someFunction().


On the other hand, this was easily 15 years ago, maybe I've just forgotten the 
question and what it was all about. It happens - I forget so much stuff these 
days.

--G.___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread Scott Ribe
On Aug 3, 2011, at 7:27 PM, Graham Cox wrote:

> In my defence, I saw this in a job interview but it was prior to 1999. Maybe 
> C99 tightened up on something that was previously vague.

Nope, been that way since K&R 1st edition ;-)

--  
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread glenn andreas

On Aug 3, 2011, at 8:27 PM, Graham Cox wrote:

> 
> On 04/08/2011, at 11:19 AM, Greg Parker wrote:
> 
>>> This is a classic question for coding job interviews.
>> 
>> Incorrect.
> 
> 
> Ah well, I guess I didn't get the job :)
> 
> In my defence, I saw this in a job interview but it was prior to 1999. Maybe 
> C99 tightened up on something that was previously vague.
> 
> --G.
> 

My copy of K&R  © 1978 says:

"More interesting are the logical connectives && and ||.  Expressions connected 
by && or || are evaluated left to right, and evaluation stops as soon as the 
truth or falsehood of the result is known.  These properties are critical to 
writing programs that work."

(p 38)

and later in Appendix A: C Reference Manual:

"Unlike &, && guarantees left-to-right evaluations; moreover the second operand 
is not evaluated if the first operand is 0"

(p190, section 7.11 Logical AND operator)

"Unlike |, || guarantees left-to-right evaluations; moreover the second operand 
is not evaluated if the first operand is non-zero"

(p191, section 7.12 Logical OR operator)


Nothing vague there.  More likely the somebody that interviewed you didn't have 
it correct in the first place, scarring you for life...


Glenn Andreas  gandr...@gandreas.com 
The most merciful thing in the world ... is the inability of the human mind to 
correlate all its contents - HPL

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread Roland King
The C99 spec I can find on the net has 6.5.13 (3) and (4). 

3. The && operator shall yield 1 if both of it's operands compare unequal to 0; 
otherwise it yields 0. The result has type int. 

4. Unlike the bitwise binary & operator, the && operator guarantees 
left-to-right evaluation; there is a sequence point after the evaluation of the 
first operand. If the firt operand compares equal to 0, the second operand is 
not evaluated. 

To my reading, and unless I have a totally bogus spec, that makes exactly the 
guarantee Jean-Daniel claims. 



On Aug 4, 2011, at 8:56, Graham Cox  wrote:

> 
> On 04/08/2011, at 1:52 AM, Jean-Daniel Dupas wrote:
> 
>> One important difference for instance is that if you write if (a() & b()), 
>> both a() and b() will always be executed, while if you write if (a() && 
>> b()), b() will be executed only if a() is true.
> 
> 
> The C language doesn't make any guarantees about that. While this 
> optimisation is to be expected, the order of execution (left to right) and 
> the optimisation (b not executed) is implementation dependent.
> 
> This is a classic question for coding job interviews.
> 
> --Graham
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org
> 
> This email sent to r...@rols.org
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread Graham Cox

On 04/08/2011, at 11:19 AM, Greg Parker wrote:

>> This is a classic question for coding job interviews.
> 
> Incorrect.


Ah well, I guess I didn't get the job :)

In my defence, I saw this in a job interview but it was prior to 1999. Maybe 
C99 tightened up on something that was previously vague.

--G.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread Greg Parker
On Aug 3, 2011, at 5:56 PM, Graham Cox wrote:
> On 04/08/2011, at 1:52 AM, Jean-Daniel Dupas wrote:
>> One important difference for instance is that if you write if (a() & b()), 
>> both a() and b() will always be executed, while if you write if (a() && 
>> b()), b() will be executed only if a() is true.
> 
> The C language doesn't make any guarantees about that. While this 
> optimisation is to be expected, the order of execution (left to right) and 
> the optimisation (b not executed) is implementation dependent.
> 
> This is a classic question for coding job interviews.

Incorrect. The C language guarantees short-circuit evaluation for '&&'. The 
left side is evaluated first. If it is false, then the right side is not 
evaluated. '||' and '?:' similarly guarantee short-circuit evaluation. 

You're correct for all other operators. '&' does not guarantee short-circuit 
evaluation or any particular order of execution.


C99 6.5.13.4 (Logical AND operator)
"Unlike the bitwise binary & operator, the && operator guarantees left-to-right 
evaluation; there is a sequence point after the evaluation of the first 
operand. If the first operand compares equal to 0, the second operand is not 
evaluated."

C99 6.5.14.4 (Logical OR operator)
"Unlike the bitwise | operator, the || operator guarantees left-to-right 
evaluation; there is a sequence point after the evaluation of the first 
operand. If the first operand compares unequal to 0, the second operand is not 
evaluated."

C99 6.5.15.4 (Conditional operator)
"The first operand is evaluated; there is a sequence point after its 
evaluation. The second operand is evaluated only if the first compares unequal 
to 0; the third operand is evaluated only if the first compares equal to 0; the 
result is the value of the second or third operand (whichever is evaluated), 
converted to the type described below.95) If an attempt is made to modify the 
result of a conditional operator or to access it after the next sequence point, 
the behavior is undefined."


-- 
Greg Parker gpar...@apple.com Runtime Wrangler


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread Graham Cox

On 04/08/2011, at 1:52 AM, Jean-Daniel Dupas wrote:

> One important difference for instance is that if you write if (a() & b()), 
> both a() and b() will always be executed, while if you write if (a() && b()), 
> b() will be executed only if a() is true.


The C language doesn't make any guarantees about that. While this optimisation 
is to be expected, the order of execution (left to right) and the optimisation 
(b not executed) is implementation dependent.

This is a classic question for coding job interviews.

--Graham


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread Jean-Daniel Dupas

Le 3 août 2011 à 16:40, Thomas Davie a écrit :

> 
> On 3 Aug 2011, at 15:15, Scott Ribe wrote:
> 
>> On Aug 3, 2011, at 7:54 AM, Thomas Davie wrote:
>> 
>>> Not really – both C ands are the same and… they're just operating on 
>>> different representations of booleans.
>> 
>> No, they're not the same at all. One is a bitwise operation on binary ints.
> 
> Yes – it performs the logical and operation on booleans represented by bits 
> (lots of booleans at once in this instance).  The other performs the same 
> logical and operation on booleans represented by entire ints.  Same op, 
> different representations.
> 



They are 2 different operators.

One important difference for instance is that if you write if (a() & b()), both 
a() and b() will always be executed, while if you write if (a() && b()), b() 
will be executed only if a() is true.


-- Jean-Daniel





___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread Thomas Davie

On 3 Aug 2011, at 15:15, Scott Ribe wrote:

> On Aug 3, 2011, at 7:54 AM, Thomas Davie wrote:
> 
>> Not really – both C ands are the same and… they're just operating on 
>> different representations of booleans.
> 
> No, they're not the same at all. One is a bitwise operation on binary ints.

Yes – it performs the logical and operation on booleans represented by bits 
(lots of booleans at once in this instance).  The other performs the same 
logical and operation on booleans represented by entire ints.  Same op, 
different representations.

Bob

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread Scott Ribe
On Aug 3, 2011, at 7:54 AM, Thomas Davie wrote:

> Not really – both C ands are the same and… they're just operating on 
> different representations of booleans.

No, they're not the same at all. One is a bitwise operation on binary ints.

-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread Thomas Davie

On 3 Aug 2011, at 14:29, Scott Ribe wrote:

> On Aug 3, 2011, at 1:53 AM, Dale Miller wrote:
> 
>> A decent language (IMHO) would not confuse things with two different "and's".
> 
> Well, there *are* two different and's, regardless of whether your favored 
> languages allow you access to both or not.

Not really – both C ands are the same and… they're just operating on different 
representations of booleans.  Any *reasonably high level* language wouldn't 
have two representations of booleans.  But that gets rather to the point of 
this – C isn't high level, for good reasons.

Bob___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread Scott Ribe
On Aug 3, 2011, at 1:53 AM, Dale Miller wrote:

> A decent language (IMHO) would not confuse things with two different "and's".

Well, there *are* two different and's, regardless of whether your favored 
languages allow you access to both or not.

-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-03 Thread Dale Miller
You are correct. I get that wrong a lot. But that reinforces my point.  
A decent language (IMHO) would not confuse things with two different  
"and's". And my typo "'1001'" for "OX1001" probably was a Freudian  
slip because of my fervent dislike of C's syntax for hex numbers. Or  
maybe it was too late into the wee hours. - Dale Miller


On Aug 2, 2011, at 23:43 , Charles Srstka wrote:

On Aug 2, 2011, at 7:57 PM, Dale Miller wrote:

It is disconcerting that if A = 0x'0110' and B = '1001' then A & B  
returns true but A && B returns 0, so "if (A && B)' is executed, the  
'true' leg is not taken


Don’t you have that backwards? Assuming B was supposed to be hex, i.e.  
0x1001, then A & B would be 0, whereas A && B would be true.


Charles







___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-02 Thread Charles Srstka
On Aug 2, 2011, at 7:57 PM, Dale Miller wrote:

> It is disconcerting that if A = 0x'0110' and B = '1001' then A & B returns 
> true but A && B returns 0, so "if (A && B)' is executed, the 'true' leg is 
> not taken

Don’t you have that backwards? Assuming B was supposed to be hex, i.e. 0x1001, 
then A & B would be 0, whereas A && B would be true.

Charles___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-02 Thread Dale Miller
Conrad Shultz notified me that I had misinterpreted Greg Parker's  
post. I will recant my accusation of hubris and apologize.


Dale Miller





___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-02 Thread Conrad Shultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 8/2/11 5:57 PM, Dale Miller wrote:
> Greg Parker wrote: "A warning on '==' inside of 'if' is ridiculous.
> '==' is comparison for equality. "=' is assignment. Anyone who can't
> at least keep these two straight shouldn't be doing programming."
...
> I think Mr Parker was guilty of hubris in his statement, and was
> totally out of line. Pride in being facile with a crummy language
> does not justify denigrating people who have finger-checks or memory
> lapses in dealing with some of C's dumber constructs.

I fear that you misinterpreted his words: he was being facetious,
somewhat satirizing a previous comment along those lines that (as far as
I can tell) was not facetious.

Please take note of the next sentence in Greg's email from which you quoted:

"One programmer's appreciated warning is another programmer's annoying
noise. If you think some warning is noise, turn it off. Please don't
belittle those of us who are not perfect."

Greg, a valuable list contributor from whom I think we all learn a great
deal, is on your side.

- -- 
Conrad Shultz

Synthetiq Solutions
www.synthetiqsolutions.com


-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFOOJ8waOlrz5+0JdURAmQFAJ9xMAHCPskIIiiO2K2fe7uyneNI+QCgiilr
y+I71h9mZdrneuWxOjZMK4s=
=TR/A
-END PGP SIGNATURE-
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Unnecessary Boolean Warning

2011-08-02 Thread Dale Miller
Greg Parker wrote: "A warning on '==' inside of 'if' is ridiculous.  
'==' is comparison for equality. "=' is assignment. Anyone who can't  
at least keep these two straight shouldn't be doing programming."
I'm glad that my bosses failed to discover my incompetence in my  
40+years of programming in FORTRAN,COBOL,CLIST,REXX,IBM360/370/Z  
Assembler, and brief forays into other languages for conversion  
projects. I've found C-based languages to be the fraught with bad  
decisions in both syntax and semantics.
'==' is comparison for equality only in C-related languages. I tend to  
think in terms of mathematics, where the '=' sign means 'comparison  
for equality'. I've been unhappy with the choice of '=' for assignment  
since learning FORTRAN many years ago. ALGOL at least used ":=" for  
assignment, which like many very good ideas got buried for  
unexplainable reasons. (Perhaps the users of those klunky teletype  
machines felt a single extra character to type was an insufferable  
burden.) Also, the idiotic basic assumption of C that 0 means false  
and not 0 means true is responsible for another mistake-prone  
construct where & means "and" in one context but it does not mean  
"and" in another, and one must instead code "&&". It is disconcerting  
that if A = 0x'0110' and B = '1001' then A & B returns true but A && B  
returns 0, so "if (A && B)' is executed, the 'true' leg is not taken.  
As I recall, at least at one point, the SOLARIS command processor  
considered that the truth value of an integer was determined by the  
low-order bit, so that 'true & true' always returned 'true' and 'A &  
B' returned the expected bit-product (BOOLEAN 'and') of A and B.
I know the difference between "=" and ""==, I just tend to relapse  
into my native and more logical language, and when forced to use a C- 
variant, I need an assistant to remind me. My grandfather immigrated  
to America from a German settlement in Russia. He insisted that the  
family learn and speak English. However, when he hit his thumb with a  
hammer, he still cried "Gott in Himmel!" I think Mr Parker was guilty  
of hubris in his statement, and was totally out of line. Pride in  
being facile with a crummy language does not justify denigrating  
people who have finger-checks or memory lapses in dealing with some of  
C's dumber constructs.


Dale Miller





___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-01 Thread Scott Ribe
On Aug 1, 2011, at 2:36 PM, Jeffrey Walton wrote:

> I wish I had a dollar for every time I lazy fingered `=` rather than
> `==`. And another buck for each time the compiler caught it (I use
> `-Wall` -Wextra` and firends).

Well, firend, I believe you ;-)

-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-01 Thread Jeffrey Walton
On Mon, Aug 1, 2011 at 4:08 PM, Greg Parker  wrote:
>
> On Aug 1, 2011, at 8:47 AM, Gordon Apple wrote:
>
>> It’s not that I object to anyone doing it, if that makes them more
>> comfortable, but a warning on ““&&” inside of “||”” is ridiculous.  Everyone
>> knows that multiplication takes precedence over addition.  “&&” is a
>> multiplication.  “||” is, welll, almost an addition.  (Exor is addition in a
>> mod 2 system.}  Anyone who can’t at least keep these two straight shouldn’t
>> be doing programming.  Overall operator precedence is a little more
>> complicated and I would recommend , for those who don’t have it all down,
>> copying the page (two page spread) out of K&E or Stroustroup and taping it
>> to the wall.  (I have done that in the past.) I just think this particular
>> warning is carrying things to the extreme.  What next?  Warning: “*” inside
>> of “+”?
>>
>> I don’t object to warnings.  “Assignment inside of “if”” is a good thing,
>> because it is a common, easily committed, error, and I appreciate the
>> warning.
>
> "A warning on `==` inside of `if` is ridiculous. `==` is comparison for 
> equality. `=` is assignment. Anyone who can't at least keep these two 
> straight shouldn't be doing programming."
>
> One programmer's appreciated warning is another programmer's annoying noise. 
> If you think some warning is noise, turn it off. Please don't belittle those 
> of us who are not perfect.
>
I wish I had a dollar for every time I lazy fingered `=` rather than
`==`. And another buck for each time the compiler caught it (I use
`-Wall` -Wextra` and firends).

Jeff
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-01 Thread Greg Parker

On Aug 1, 2011, at 8:47 AM, Gordon Apple wrote:

> It’s not that I object to anyone doing it, if that makes them more
> comfortable, but a warning on ““&&” inside of “||”” is ridiculous.  Everyone
> knows that multiplication takes precedence over addition.  “&&” is a
> multiplication.  “||” is, welll, almost an addition.  (Exor is addition in a
> mod 2 system.}  Anyone who can’t at least keep these two straight shouldn’t
> be doing programming.  Overall operator precedence is a little more
> complicated and I would recommend , for those who don’t have it all down,
> copying the page (two page spread) out of K&E or Stroustroup and taping it
> to the wall.  (I have done that in the past.) I just think this particular
> warning is carrying things to the extreme.  What next?  Warning: “*” inside
> of “+”?
> 
> I don’t object to warnings.  “Assignment inside of “if”” is a good thing,
> because it is a common, easily committed, error, and I appreciate the
> warning.

"A warning on `==` inside of `if` is ridiculous. `==` is comparison for 
equality. `=` is assignment. Anyone who can't at least keep these two straight 
shouldn't be doing programming."

One programmer's appreciated warning is another programmer's annoying noise. If 
you think some warning is noise, turn it off. Please don't belittle those of us 
who are not perfect.


-- 
Greg Parker gpar...@apple.com Runtime Wrangler


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-01 Thread Jean-Daniel Dupas
If this warning bother you, just disable it.

clang is smart enough to tell you what flag you have to turn off in the warning 
message.

For instance, just add -Wno-constant-logical-operand in your other warning 
flags.


Le 1 août 2011 à 17:47, Gordon Apple a écrit :

> It’s not that I object to anyone doing it, if that makes them more
> comfortable, but a warning on ““&&” inside of “||”” is ridiculous.  Everyone
> knows that multiplication takes precedence over addition.  “&&” is a
> multiplication.  “||” is, welll, almost an addition.  (Exor is addition in a
> mod 2 system.}  Anyone who can’t at least keep these two straight shouldn’t
> be doing programming.  Overall operator precedence is a little more
> complicated and I would recommend , for those who don’t have it all down,
> copying the page (two page spread) out of K&E or Stroustroup and taping it
> to the wall.  (I have done that in the past.) I just think this particular
> warning is carrying things to the extreme.  What next?  Warning: “*” inside
> of “+”?
> 
> I don’t object to warnings.  “Assignment inside of “if”” is a good thing,
> because it is a common, easily committed, error, and I appreciate the
> warning.
> 
> 
> On 7/31/11 8:15 PM, "Graham Cox"  wrote:
> 
>> 
>> On 01/08/2011, at 6:13 AM, Gordon Apple wrote:
>> 
>>> Anybody who understands
>>> basic boolean operator precedence knows this is unnecessary.
>> 
>> 
>> True, but who does? I mean, sure, if everyone who ever sees your source has
>> that fully committed to heart, you're golden. Otherwise, what's the harm of a
>> few brackets to make it absolutely clear? It's not as if it makes any
>> difference to the object code. Code for readability.
>> 
>> --Graham
>> 
>> 
>> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/devlists%40shadowlab.org
> 
> This email sent to devli...@shadowlab.org

-- Jean-Daniel




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-01 Thread Sean McBride
On Sun, 31 Jul 2011 15:13:45 -0500, Gordon Apple said:

>The following expression generates a warning message (3&&2 within 3||2) and
>says to include the 3anded2 expression in parens.  Anybody who understands
>basic boolean operator precedence knows this is unnecessary.  Bug report?
>
>BOOL isInUse = [super mediaIsInUse];
>isInUse = isInUse || [self videoIsOn] && ([[self capMgr] isRecording]
>  || [[self camVC]
>movieIsPlaying]
>  || [[self camVC]
>movieIsPaused]);

This warning has found several bugs (ie incorrect programmer recollection of 
precedence rules) in at least 2 open source projects I use.  I'm glad we have 
it.  Turn it off it offends you so.

--

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com
Mac Software Developer  Montréal, Québec, Canada


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-08-01 Thread Gordon Apple
It¹s not that I object to anyone doing it, if that makes them more
comfortable, but a warning on ³³&&² inside of ³||²² is ridiculous.  Everyone
knows that multiplication takes precedence over addition.  ³&&² is a
multiplication.  ³||² is, welll, almost an addition.  (Exor is addition in a
mod 2 system.}  Anyone who can¹t at least keep these two straight shouldn¹t
be doing programming.  Overall operator precedence is a little more
complicated and I would recommend , for those who don¹t have it all down,
copying the page (two page spread) out of K&E or Stroustroup and taping it
to the wall.  (I have done that in the past.) I just think this particular
warning is carrying things to the extreme.  What next?  Warning: ³*² inside
of ³+²?

I don¹t object to warnings.  ³Assignment inside of ³if²² is a good thing,
because it is a common, easily committed, error, and I appreciate the
warning.


On 7/31/11 8:15 PM, "Graham Cox"  wrote:

> 
> On 01/08/2011, at 6:13 AM, Gordon Apple wrote:
> 
>> Anybody who understands
>> basic boolean operator precedence knows this is unnecessary.
> 
> 
> True, but who does? I mean, sure, if everyone who ever sees your source has
> that fully committed to heart, you're golden. Otherwise, what's the harm of a
> few brackets to make it absolutely clear? It's not as if it makes any
> difference to the object code. Code for readability.
> 
> --Graham
> 
> 
> 


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-07-31 Thread Graham Cox

On 01/08/2011, at 6:13 AM, Gordon Apple wrote:

> Anybody who understands
> basic boolean operator precedence knows this is unnecessary.


True, but who does? I mean, sure, if everyone who ever sees your source has 
that fully committed to heart, you're golden. Otherwise, what's the harm of a 
few brackets to make it absolutely clear? It's not as if it makes any 
difference to the object code. Code for readability.

--Graham


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-07-31 Thread Glenn L. Austin
On Jul 31, 2011, at 1:13 PM, Gordon Apple wrote:

> The following expression generates a warning message (“&&” within “||”) and 
> says to include the “anded” expression in parens.  Anybody who understands 
> basic boolean operator precedence knows this is unnecessary.  Bug report?
> 
>BOOL isInUse = [super mediaIsInUse];
> isInUse = isInUse || [self videoIsOn] && ([[self capMgr] isRecording] 
>   || [[self camVC] 
> movieIsPlaying] 
>   || [[self camVC] 
> movieIsPaused]);

I agree that it is unnecessary, but a lot of the warnings that are now provided 
are unnecessary but promote better and less ambiguous coding practices.


-- 
Glenn L. Austin, Computer Wizard and Race Car Driver <><




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unnecessary Boolean Warning

2011-07-31 Thread Gordon Apple
Sorry, that should have been posted to Xcode.

On 7/31/11 3:13 PM, "Gordon Apple"  wrote:

> The following expression generates a warning message (³&&² within ³||²) and
> says to include the ³anded² expression in parens.  Anybody who understands
> basic boolean operator precedence knows this is unnecessary.  Bug report?
> 
> BOOL isInUse = [super mediaIsInUse];
> isInUse = isInUse || [self videoIsOn] && ([[self capMgr] isRecording]
>   || [[self camVC] movieIsPlaying]
>   || [[self camVC]
> movieIsPaused]);
> 


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Unnecessary Boolean Warning

2011-07-31 Thread Gordon Apple
The following expression generates a warning message (³&&² within ³||²) and
says to include the ³anded² expression in parens.  Anybody who understands
basic boolean operator precedence knows this is unnecessary.  Bug report?

BOOL isInUse = [super mediaIsInUse];
isInUse = isInUse || [self videoIsOn] && ([[self capMgr] isRecording]
  || [[self camVC]
movieIsPlaying] 
  || [[self camVC]
movieIsPaused]);


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com