Skip to Content
Practical C Programming, 3rd Edition
book

Practical C Programming, 3rd Edition

by Steve Oualline
August 1997
Beginner
454 pages
9h 32m
English
O'Reilly Media, Inc.
Content preview from Practical C Programming, 3rd Edition

Chapter 23. Programming Adages

Second thoughts are ever wiser.

Euripides

General

  • Comment, comment, comment. Put a lot of comments in your program. They tell other programmers what you did. 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.

  • Use the prefix version of ++ and -- (++x, --x) instead of the postfix version (x++, x--). This adage does nothing for you in C, but will serve you well when you move to C++.

  • 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 or statement.

    for (index = 0; data[index] < key; ++index) 
            continue;

Design

  • When designing your program, keep in mind “The Law of Least Astonishment,” which states that your program should behave in a way that least astonishes the user.

  • Make the user interface as simple and consistent as possible.

  • Give the user as much help as you can.

  • Clearly identify all error messages with the word “error,” and try to give the user some idea of how to correct his problem.

Declarations

  • Put one variable declaration per line, and comment them.

  • Make variable-names long enough to be ...

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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Practical C Programming

Practical C Programming

B. M. Harwani

Publisher Resources

ISBN: 1565923065Errata Page