|
Softpanorama
(slightly skeptical)
Open Source Software Educational Society |
May the
source be with you,
but remember the KISS principle ;-)
|

|
The Elements of Programming Style
by Brian W. Kernighan and P.J. Plauger
|
-
The Elements of Programming Style
-
Brian W. Kernighan, P. J. Plauger / Paperback / Published 1988
Amazon Price: $40.74
Published in 1978. 168 pages.
Was first published in 1979. Now slightly outdated.
Code Complete : A Practical Handbook of Software Construction contains
similar material if you want a more recent book, but this book pioneered
the field. Contains an interesting discussion of how to transform the program
to a better one and common pitfalls in programming. The authors have provided
an useful set of tips for coding (and sometimes design). Here is a summary
of the important programming style tips from Brian Kernighan's 1994 guest
CS50 lecture:
-
Say what you mean, simply and directly.
- Use the "telephone test'' for readability.
- Write clearly - don't be too clever.
- Don't use conditional expressions as a substitute for a logical
expression.
- Parenthesize to avoid ambiguity.
- Each time you make a test, do something.
- Follow each decision as closely as possible with its associated
action.
- Use the good features of a language; avoid the bad ones.
- Capture regularity in control flow, irregularity in data.
- Each module should do one thing well.
- Make sure comments and code agree.
- Don't just echo the code with comments - make every comment
count.
- Don't comment bad code - rewrite it.
- Use symbolic constants for magic numbers.
- Watch out for side effects and order of evaluation.
- Macros are not functions.
- Watch out for off-by-one errors.
- Test programs at their boundaries.
- Program defensively.
- Make sure input cannot violate the limits of the program.
- Make it right before you make it faster.
- Keep it right when you make it faster.
- Don't sacrifice clarity for small gains in ``efficiency.''
- Don't stop with your first draft.
Recommended Links
Brian Kernighan homepage
-
Why Pascal is Not My Favorite Programming Language
-
Indian Hill C Style and Coding Standards
-
Optimization
of Computer Programs in C
-
Rob Pike Notes on Programming in C
-
The Ten Commandments for C Programmers (Annotated Edition)
Dennis Ritchie
Home Page
freshmeat.net Project details for The Elements of Programming Style - fortune
cookie
The Elements of Programming Style - fortune cookie is a fortune cookie
file containing the 69 tips from the "Elements of Programming Style"
by Kernighan & Plaugher.
Copyright © 1996-2009 by Dr. Nikolai Bezroukov.
www.softpanorama.org was
created as a service to the UN Sustainable Development Networking Programme (SDNP)
in the author free time.
Submit
comments This document is an industrial compilation designed and created
exclusively for educational use and is placed under the copyright of the
Open Content License(OPL).
Site uses AdSense so you need to be aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made
for educational purposes only in compliance with the fair use doctrine.
Disclaimer:
- The statements, views and opinions presented on
this web page are those of the author and are not endorsed by, nor do they necessarily
reflect, the opinions of the author present and former employers, SDNP or any other
organization the author may be associated with.
- We do not warrant the correctness of the information provided or its
fitness for any purpose
- In no way this site is associated with or endorse cybersquatters
using
the term "softpanorama" with other main or country domains (e.g. softpanorama.com) with
bad faith intent to profit from the goodwill belonging to
someone else.
Last modified:
August 11, 2009