Skip to Main Content
Practical C++ Programming, 2nd Edition
book

Practical C++ Programming, 2nd Edition

by Steve Oualline
December 2002
Beginner to intermediate content levelBeginner to intermediate
576 pages
14h 6m
English
O'Reilly Media, Inc.
Content preview from Practical C++ Programming, 2nd Edition

Chapter 30. Programming Adages

Second thoughts are ever wiser.

Euripides

This chapter consists of guidelines and rules for practical programming.

General

  • Comment, comment, comment. Put a lot of comments in your program. They tell other programmers what you did, and they also tell you what you did.

  • Use the “KISS” principle (Keep It Simple, Stupid). Clear and simple is better than complex and wonderful.

  • Avoid side effects. Use ++ and -- on lines by themselves.

  • Never put an assignment inside a conditional. Never put an assignment inside any other statement.

  • Know the difference between = and = =. Using = for = = is a very common mistake and is difficult to find.

  • Never do “nothing” silently:

    // Don't program like this
    for (index = 0; data[index] < key; ++index); 
    // Did you see the semicolon at the end of the last line?

    Always put in a comment:

    for (index = 0; data[index] < key; ++index) 
            /* Do nothing */;
  • Practice coding. Practice is crucial for people involved in almost every other profession that requires a significant level of skill and creativity (e.g., artists, athletes). Help others learn to program. It’s good practice for you to go over what you already know, or think you know.

Design

  • If you come to a choice between a relatively “quick hack” or a somewhat more involved but more flexible solution, always go for the more flexible solution. You’re more likely to reuse it or learn from it. You’re also more likely to be thankful later on when requirements shift a little and your code is ready ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Discovering Modern C++, 2nd Edition

Discovering Modern C++, 2nd Edition

Peter Gottschling

Publisher Resources

ISBN: 0596004192Supplemental ContentErrata Page