Free Trial

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

Share this Page URL
Help

Chapter 24. Common Practices > Programming with Style - Pg. 603

Programming with Style 603 · · · · · · · · Allow arguments to come from either the command line or standard input. Don't put arbitrary limitations into your program. Prefer variable-length fields over fixed-length fields. Use text-oriented network protocols. Tell everyone else to use text-oriented network protocols! Tell everyone else to tell everyone else to use text-oriented network proto- cols!!! Be vicariously lazy. Be nice. Programming with Style You'll certainly have your own preferences in regard to formatting, but there are some general guidelines that will make your programs easier to read, understand, and maintain. The most important thing is to run your programs under the use warnings pragma. (You can turn off unwanted warnings with no warnings .) You should also always run under use strict or have a good reason not to. The use sigtrap and even the use diagnostics pragmas may also prove of benefit. Regarding aesthetics of code layout, about the only thing Larry cares strongly about is that the closing brace of a multiline BLOCK should be "outdented" to line up with the keyword that started the construct. Beyond that, he has other prefer- ences that aren't so strong. Examples in this book (should) all follow these coding conventions: · · Use four-column indents. An opening brace should be put on the same line as its preceding keyword, if possible; otherwise, line them up vertically. while ($condition) { # do something } # for short ones, align with keywords # if the condition wraps, line up the braces with each other while ($this_condition and $that_condition and $this_other_long_condition) { # do something }