Click here to Skip to main content
Click here to Skip to main content

The seven secrets of successful programmers

, 20 Oct 2003 CPOL
Rate this:
Please Sign up or sign in to vote.
7 tips to make you a better citizen in the developer community.

1. Code for human consumption

It is one of the most pervasive misunderstandings in computing that the source code is for the computer's consumption. Computers work with low-level binary code, a series of impenetrable 1's and 0's or hexadecimal numbers, not the structured high level languages we code in. The reason that these languages were developed was to help the programmer.

In practice, coding for human consumption often means coding for clarity first, over efficiency and speed second.

2. Comment often and comment well

The comment is the extreme example of a language element for human consumption. Most compilers will strip the comments from the executable program. The purpose of the comment is to tell you (and any future developer) what the program is intended to do. Write comments with this in mind - and avoid simply restating the code.

  • Good comment: Disable button to prevent its activation.
  • Bad comment: Set cmd = False

A good indication that you have got the level of comment right: could someone understand what your program does if all but the comments were removed?

3. Layout code to increase legibility

Just as it is important for an author to split a book into chapters and paragraphs that aid reading so it is important for the developer to consider the layout of the code and how that can aid readability of the code. In particular, any code branch (an IF..THEN...ELSE construction) and any code repetition (a WHILE...END WHILE construction) should be indented so that it is easy to see where they start and end.

4. Expect the unexpected and deal with it

Before you open a file, make sure that the file is present. Before you set focus to a control, make sure that the control is visible and enabled. Try to work out what conditions could cause your code to fail and test for them before they cause the program to fall over. Also use explicit data type conversion wherever possible.

5. Name your variables to aid readability

There are a number of strategies to variable naming. The key is to be consistent and to be as informative as possible. If you name a variable nMonth, you give the programmer extra information as to what that variable is expected to contain. I personally prefer the Hungarian notation style - but whichever style you use, consistency is the key.

6. Keep your functions and subroutines simple

A function or subroutine should ideally only do one thing. One of the greatest sources of misunderstandings, in my experience, is a subroutine that does a number of different operations. This should be split into separate functions for each different thing it is doing, so that these in turn are easy to reuse, and the scope of a code change is easy to understand.

7. Scope functions and variables appropriately

Functions and variables that are only used in one module should not be visible outside that module. Variables that are only used in a function or subroutine should not be visible outside that function or subroutine. This prevents any use of a variable or function outside of where it makes sense to use it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Duncan Edwards Jones
Software Developer (Senior)
Ireland Ireland
C# / SQL Server developer
Microsoft MVP 2006, 2007
Visual Basic .NET
Follow on   Twitter   LinkedIn

Comments and Discussions

GeneralVB6 help PinsussAnonymous1-Jul-04 8:19 
GeneralRe: VB6 help PinmemberMerrion22-Mar-05 6:36 
GeneralCode Complete Pinmemberedunphy1930-Oct-03 8:15 
GeneralSeperate data from code Pinmembertwb1529-Oct-03 20:45 
Generalsmartass remark Pinmemberk4_pacific29-Oct-03 3:08 
GeneralRe: smartass remark PinmemberMerrion29-Oct-03 7:46 
GeneralType of comments Pinmembergaryknights22-Oct-03 4:24 
GeneralRe: Type of comments PinmemberKevin McFarlane27-Oct-03 23:46 
GeneralCosmetic ... PinmemberSébastien Lorion21-Oct-03 11:00 
GeneralRe: Cosmetic ... PinmemberTom Pruett22-Oct-03 4:16 
GeneralRe: Cosmetic ... PinmemberSébastien Lorion22-Oct-03 20:06 
GeneralRe: Cosmetic ... PinmemberTom Pruett23-Oct-03 8:07 
GeneralRe: Cosmetic ... PinmemberSébastien Lorion23-Oct-03 11:30 
GeneralRe: Cosmetic ... Pinmemberrichman229-May-04 4:28 
GeneralRe: Cosmetic ... PinmemberKevin McFarlane28-Oct-03 0:02 
GeneralRe: Cosmetic ... PinmemberKevin McFarlane27-Oct-03 23:59 
GeneralPoint #2 Pinmemberrondalescott21-Oct-03 6:58 
GeneralRe: Point #2 PinsussAnonymous21-Oct-03 7:29 
GeneralRe: Point #2 PinmemberMichael P Butler21-Oct-03 7:41 
GeneralRe: Point #2 PinmemberKevin McFarlane28-Oct-03 0:13 
GeneralRe: Point #2 Pinmemberdanitrol28-Oct-03 20:54 
GeneralRe: Point #2 PinmemberPit M.21-Oct-03 22:46 
GeneralRe: Point #2 PinmemberArnaud Brejeon21-Oct-03 23:41 
GeneralRe: Point #2 PinmemberKevin McFarlane28-Oct-03 0:25 
GeneralRe: Point #2 Pinmemberjhwurmbach29-Oct-03 21:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.141022.2 | Last Updated 21 Oct 2003
Article Copyright 2002 by Duncan Edwards Jones
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid