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

Some habits of successful programmers

, 23 Feb 2015 CPOL
Rate this:
Please Sign up or sign in to vote.
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 cleverness second.  This is not to condone bad / inneficient code but rather to address premature optimization and optimization that costs maintainability. 

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 the update command until the record needs to be saved.
  • Bad comment: Set cmd enabled = False

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

It is a commonly expressed statement that we should have "self documenting" code but bear in mind that the code can only tell you what the code does - not why.

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.

Code should be split across files (and indeed across the file system - use sub folders under your solution where that makes sense)

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 and functions 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 MonthNumber, you give the programmer extra information as to what that variable is expected to contain.  The key point is to use the name to indicate what the variable is used for.

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.

If you declare anything as public you are responsible for how it can be used - preventing invalid data states, race conditions and so on. 

8. Test as much as possible, as soon as possible

If you an adherent of Test Driven Development you already have this but even for those not following TDD there is great value in testing as much of your code as soon as you can.  This means unit testing in the IDE before any code change is checked in and also maintaining a safety net of tests over all the existing functionality to  make sure your latest changes don't break anything. 

You should also include instrumentation or use a code profiler to see how well your application is running.  In my experience performance issues are often introduced gradually in the middle of code changes to fix other issues.

9.  Keep growing

Software development is still a young industry and best practice is still subject to change.  When a new magic silver bullet programming language or achitecture pattern comes along - give it a try with an open mind.  There is much still left to discover.


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

QuestionAmen Pinmemberd_c_j26-Feb-15 4:33 
General"The comment is the extreme example of a language element" PinprofessionaljediYL24-Feb-15 21:14 
GeneralComment often and well: another perspective PinmemberWestieBoy8-Nov-14 19:02 
GeneralRe: Comment often and well: another perspective PinprofessionalDuncan Edwards Jones21-Nov-14 20:11 
GeneralMy vote of 5 PinprofessionalEdward Quixote7-Nov-14 0:17 
QuestionA comment very rarely be needed if the code is clean and readable.. PinmemberBlake A Niemyjski6-Nov-14 13:53 
AnswerRe: A comment very rarely be needed if the code is clean and readable.. PinprofessionalDuncan Edwards Jones6-Nov-14 21:26 
GeneralRe: A comment very rarely be needed if the code is clean and readable.. PinmemberSteve07287-Nov-14 7:18 
AnswerRe: A comment very rarely be needed if the code is clean and readable.. Pinmemberjnlt24-Feb-15 12:50 
GeneralMy vote of 4 [modified] Pinprofessional i006-Nov-14 12:37 
GeneralRe: My vote of 4 PinprofessionalDuncan Edwards Jones6-Nov-14 21:23 
GeneralRe: My vote of 4 Pinprofessional i006-Nov-14 21:59 
GeneralRe: My vote of 4 PinprofessionalDuncan Edwards Jones6-Nov-14 22:51 
GeneralMy vote of 5 PinprofessionalJörgen Andersson6-Nov-14 8:07 
GeneralRe: My vote of 5 PinprofessionalDuncan Edwards Jones6-Nov-14 12:35 
GeneralVB6 help PinsussAnonymous1-Jul-04 9:19 
GeneralRe: VB6 help PinmemberMerrion22-Mar-05 7:36 
GeneralCode Complete Pinmemberedunphy1930-Oct-03 9:15 
GeneralSeperate data from code Pinmembertwb1529-Oct-03 21:45 
GeneralRe: Seperate data from code PinprofessionalDuncan Edwards Jones6-Nov-14 21:28 
Generalsmartass remark Pinmemberk4_pacific29-Oct-03 4:08 
GeneralRe: smartass remark PinmemberMerrion29-Oct-03 8:46 
GeneralType of comments Pinmembergaryknights22-Oct-03 5:24 
GeneralRe: Type of comments PinmemberKevin McFarlane28-Oct-03 0:46 
GeneralCosmetic ... PinmemberSébastien Lorion21-Oct-03 12:00 
GeneralRe: Cosmetic ... PinmemberTom Pruett22-Oct-03 5:16 
GeneralRe: Cosmetic ... PinmemberSébastien Lorion22-Oct-03 21:06 
GeneralRe: Cosmetic ... PinmemberTom Pruett23-Oct-03 9:07 
GeneralRe: Cosmetic ... PinmemberSébastien Lorion23-Oct-03 12:30 
GeneralRe: Cosmetic ... Pinmemberrichman229-May-04 5:28 
GeneralRe: Cosmetic ... PinmemberKevin McFarlane28-Oct-03 1:02 
GeneralRe: Cosmetic ... PinmemberKevin McFarlane28-Oct-03 0:59 
GeneralPoint #2 Pinmemberrondalescott21-Oct-03 7:58 
GeneralRe: Point #2 PinsussAnonymous21-Oct-03 8:29 
GeneralRe: Point #2 PinmemberMichael P Butler21-Oct-03 8:41 
GeneralRe: Point #2 PinmemberKevin McFarlane28-Oct-03 1:13 
GeneralRe: Point #2 Pinmemberdanitrol28-Oct-03 21:54 
GeneralRe: Point #2 PinmemberPit M.21-Oct-03 23:46 
GeneralRe: Point #2 PinmemberArnaud Brejeon22-Oct-03 0:41 
I also quite disagree with Point #2.
Comments are very tricky because they often are not updated. I've seen many times the following happen many times.
When the code is written from sratch, the author comments very nicely. Then bugs fixing comes in the process and modifications in the code are made without updating the code (developpers hate bugs in their code and try to fix them as quickly as possible!). In the end the comments don't make sense at all.
I think this is much worse than no comment at all and frankly it happens all the time.
I believe in short functions that do a simple task and have a proper name describing precisely the task.
GeneralRe: Point #2 PinmemberKevin McFarlane28-Oct-03 1:25 
GeneralRe: Point #2 Pinmemberjhwurmbach29-Oct-03 22:14 
GeneralRe: Point #2 PinmemberKevin McFarlane30-Oct-03 1:02 
GeneralRe: Point #2 Pinmemberjhwurmbach30-Oct-03 1:08 
GeneralRe: Point #2 Pinmembercomputerguru9238216-Aug-05 18:10 
GeneralRe: Point #2 PinmemberKevinHall23-Oct-03 10:14 
QuestionWhat about test first ? Pinmembermcarbenay4-May-03 4:28 
AnswerRe: What about test first ? PinmemberMerrion2-Oct-03 4:23 
GeneralAnd ... use English for comments etc. PinmemberAlexander Bischofberger15-Dec-02 23:29 
GeneralRe: And ... use English for comments etc. PinmemberDieter Hammer21-Oct-03 8:09 
GeneralRe: And ... use English for comments etc. Pinmemberjhwurmbach21-Oct-03 23:05 

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 | Terms of Use | Mobile
Web03 | 2.8.150331.1 | Last Updated 23 Feb 2015
Article Copyright 2002 by Duncan Edwards Jones
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid