• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C


  • Subject: Re: C
  • From: "Alastair J.Houghton" <email@hidden>
  • Date: Fri, 29 Aug 2003 23:21:36 +0100

On Friday, August 29, 2003, at 08:55 pm, David Thorp wrote:

Actually, I've just tested it without the parentheses in the while condition, and it still works. Guess I was wrong about that precedence comment.

Yep.

Still, I believe it's wise to put the parentheses in anyway, if for no other reason than it's easier to read,

No, it isn't. A lot of people make this assertion, but the fact is that it's easier to *write* (because you don't have to think), and *not* easier to read. Consider, for example

(a - g + b * c + d / (h + i * j)) * e - f

vs

(((a - g) + (b * c) + (d / (h + (i * j)))) * e) - f

The former is very obviously easier to read. Even a Lisp programmer would balk at the latter ;-)

It isn't safer either; if I'm working on some code that contains an expression like the latter, there is an increased risk that I will accidentally move one of the brackets to the wrong place whilst editing it. Even bracket-matching in editors doesn't mitigate that risk---all that tells you is that the expression isn't balanced (so you need to add a bracket somewhere)... it doesn't tell you *where* to add it, and it's very easy to make the wrong choice.

but also helps you be sure you've got it right.

It helps me to be sure that I get expressions right if I *know* at least the basic rules regarding the use of operators in C. Now, there are obscure cases (for example, a & b && c = what?), and in those cases, extra brackets are arguably OK, but for the common cases you really should know the rules.

Anyway, for the benefit of those that don't have one already, here's a precedence table:

http://www.alastairs-place.net/blog/stuff/C Operator Precedence.pdf

(I believe it's correct; please let me know if you spot a mistake...)

Kind regards,

Alastair.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: C (From: David Thorp <email@hidden>)

  • Prev by Date: How can I tell when my window has finished drawing?
  • Next by Date: Newbie question: forcing data format during saveDocumentTo:
  • Previous by thread: Re: C
  • Next by thread: Re: C
  • Index(es):
    • Date
    • Thread