You are here:  OakRoadSystems > Programming > C++ Practices > 2/Principles
 
  Home
  Site Map
  Shareware Utils
  Articles
      Programming
      Internet
      Mathematics
      General
  Search

2. Fundamental Principles

revised 15 Feb 2001
Copyright © 1998-2002 Stan Brown, Oak Road Systems

 

Programming practices don't exist for their own sake -- or at least they shouldn't. This page lists my Koding Kreed.

Hide information.

This is what encapsulation is all about. Be like the civil service in Yes, Prime Minister -- guard information jealously and release it only grudgingly and on a need-to-know basis, but make sure that what you do release can't get you into trouble.

Reuse code.

It's better to use somebody else's code than to write my own. The best "somebody else" is the standard C++ library.

Be nice to clients, even if it takes extra work.

A "client" of code is any other piece of code that uses it or depends on it. Since any given piece of code (including a header file) should have more users than implementors, the implementor should expend a little effort to save trouble for the clients.

C++ is not C.

I will not write C code, compile it with a C++ compiler, and try to pretend that it's C++.

Promote code safety.

The compiler is very good at checking certain things, like types and const-ness (which is part of typing). I will write my code using safer alternatives whenever possible. I will try to anticipate run-time problems and capture them in a way that serves the user best.

Promote code robustness.

Robust code is written to adapt itself readily to unforeseen changes, to let new code be added without having to make major changes in existing code.

Worry about correctness before efficiency.

It doesn't matter how fast it is if it doesn't do the right thing. (Anyway the compiler can usually do a better job of optimizing than I can.) But I'll follow certain well-known practices that help the compiler optimize.

previous   contents     C++ Practices
 contact info  |  site map
Valid HTML 4.0! this page: http://oakroadsystems.com/codeprac/princ.htm