Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 12: Code Construction > Block and Statement Style Guidelines

Block and Statement Style Guidelines

As mentioned previously, the “emulating block boundaries” style works well for most block-structured languages.

  • Use more parentheses than you think you’ll need. I especially use parentheses around all my arithmetic expressions – mostly just to make sure I haven’t screwed up the precedence rules.
    fx = ((a + b) * (c + d)) / e;
  • Format single statement blocks consistently. Using the emulating block-boundaries technique:
    if (average > MIN_AVG) {
         avg = MIN_AVG;
    }
  • For complicated conditional expressions, put separate conditions on separate lines.
    if ((’0’ <= inChar && inChar <= ’9’) ||
         (’a’ <= inChar && inChar <= ’z’) ||
         (’A’ <= inChar && inChar <= ’Z’)) {
              mytext.addString(inChar);
              mytext.length++;
    }

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial