Beta

Slashdot: News for Nerds

×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

parenthesis

SJS (1851) writes | more than 6 years ago

Programming 0

I ran across http://wordaligned.org/articles/brackets-off and, well, I disagree.

"Thomas Guest" writes:

And secondly, if a coding standard were to rule on how to parenthesise, it would be difficult to find a middle ground. This leaves as candidate rules the two extremes:

1. parenthesise everything
2. never parenthesise

The first quickly leads to unreadable code. The second seems overly proscriptive.

I ran across http://wordaligned.org/articles/brackets-off and, well, I disagree.

"Thomas Guest" writes:

And secondly, if a coding standard were to rule on how to parenthesise, it would be difficult to find a middle ground. This leaves as candidate rules the two extremes:

1. parenthesise everything
2. never parenthesise

The first quickly leads to unreadable code. The second seems overly proscriptive.

Thomas misses the obvious middle-ground: parenthesize everything where order matters.

Sure,

x = ((((a * b) * c) + e) + f);

may be overkill, but even the most passionate parenthesize everything advocates don't go that far; they write

x = ( a * b * c ) + e + f;

where every operation at the same level of precedence is left alone. This provides maximal clarity and promotes readability, as the reader doesn't have to think about the order of precedence for that language.

He then goes on to discuss order of precedence as if it's a universal rule, rather than a convention of infix notation in programming languages. (I've had this discussion with people, some of whom could not be convinced that precedence was anything other than a convention, arguing that it derives from fundamental principles of mathematics that I was too stupid to comprehend and thus it wasn't worth explaining.)

Perhaps Thomas should try programming in more than just one language. I suggest Smalltalk.

cancel ×

0 comments

Check for New Comments
Slashdot Account

Need an Account?

Forgot your password?

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>
Create a Slashdot Account

Loading...