7B Software Programmer's Style Guide

Mark Smith
mark.smith (at) 7Bsoftware.com
Last modification: 2010 July 3

1.0 Introduction: The Local Idiom

This paper describes elements of programming style that are strongly suggested for all software that we will write.

An emphasis is placed on techniques that tend to reduce bugs, improve program maintenance, and are visually pleasing. In some cases the only goal of a particular programming style recommendation is the visual aspect. For these recommendations, there may well be reasonable competing techniques. However, we believe that it is crucial that the software we deliver have a certain uniformity in style, both for the benefit of the customer and for the benefit of those who would maintain your software.

This is probably a good time to talk a bit about programming philosophy. The goal of this style guide is not to be a workaid for code reviews. To the contrary, we believe that detailed, formal code walkthroughs do not typically generate much benefit. (In fact, experience teaches us that there usually should be only one of the following two actions from a code review: "Continue Programming" or "Start Over From Scratch".)

The main goal of this style guide is instead a preemptive strike against non-uniform techniques, but more as a teaching tool than as a compliance tool. It should be read once, before writing any software, and then referred to periodically when questions come up. I also expect that this guide will contain errors and omissions. And it's expected that we might develop some new style techniques as we experiment with new ideas or programming language idioms. This guide is not so much a bible, as it is a collection of what we know works well and looks good.

A good name for what this guide is promoting is "the Local Idiom"; that is, software written in the 7B Software style. We know this isn't the only way to do it. It's the way that we do it.

Some of the material in this guide are targeted more for newer programmers, so please don't be insulted if a lot of this is old news to you.

2.0 Some Programming Concepts

Before I jump into coding techniques, I want to talk a bit about some basic concepts, because they affect how the code is written in a general way (though they aren't coding techniques per se).

2.1 Avoid committing experimental code for things you don't understand.

(By commit I refer to publishing source code in the source code repository.)

This is a problem that can very easily afflict a new Tcl/Tk programmer, because it is extremely easy in that language to just try things out, re-test, and stop coding when the GUI looks right.

This is never a good idea. It is OK to do code experimentation when you're trying to understand how some widget works. But it is not OK to quit before you actually understand, and commit the experimental code to the CVS tree.

2.2 Every job is a 2-person job.

I've seen lots of projects where one person was basically in charge of writing software, writing the unit test, writing the interface guide, doing the testing, and writing the installation procedure.

This is not a good idea. It violates the First Rule of Reliability: Do not have a single point of failure. In this case, of course, the single point of failure is the programmer.

Earlier, I said that I'm not a big believer in formal code reviews. You don't need code reviews to avoid single points of failure. All you really need are two things: