5,136,421 members and growing! (11,975 online)
Email Password   helpLost your password?
General Programming » Programming Tips » General     Intermediate

The seven secrets of successful programmers

By Duncan Edwards Jones

7 tips to make you a better citizen in the developer community.
Windows, Dev

Posted: 12 Dec 2002
Updated: 20 Oct 2003
Views: 90,828
Announcements



Search    
Advanced Search
Sitemap
54 votes for this Article.
Popularity: 4.74 Rating: 2.74 out of 5
22 votes, 40.7%
1
4 votes, 7.4%
2
7 votes, 13.0%
3
10 votes, 18.5%
4
11 votes, 20.4%
5

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Duncan Edwards Jones


Microsoft MVP 2006, 2007
Visual Basic .NET
Occupation: Software Developer (Senior)
Location: Ireland Ireland

Other popular Programming Tips articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 93 (Total in Forum: 93) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralVB6 helpsussAnonymous9:19 1 Jul '04  
GeneralRe: VB6 helpmemberMerrion7:36 22 Mar '05  
GeneralCode Completememberedunphy199:15 30 Oct '03  
GeneralSeperate data from codemembertwb1521:45 29 Oct '03  
Generalsmartass remarkmemberk4_pacific4:08 29 Oct '03  
GeneralRe: smartass remarkmemberMerrion8:46 29 Oct '03  
GeneralType of commentsmembergaryknights5:24 22 Oct '03  
GeneralRe: Type of commentsmemberKevin McFarlane0:46 28 Oct '03  
GeneralCosmetic ...memberSébastien Lorion12:00 21 Oct '03  
GeneralRe: Cosmetic ...memberTom Pruett5:16 22 Oct '03  
GeneralRe: Cosmetic ...memberSébastien Lorion21:06 22 Oct '03  
GeneralRe: Cosmetic ...memberTom Pruett9:07 23 Oct '03  
GeneralRe: Cosmetic ...memberSébastien Lorion12:30 23 Oct '03  
GeneralRe: Cosmetic ...memberrichman25:28 29 May '04  
GeneralRe: Cosmetic ...memberKevin McFarlane1:02 28 Oct '03  
GeneralRe: Cosmetic ...memberKevin McFarlane0:59 28 Oct '03  
GeneralPoint #2memberrondalescott7:58 21 Oct '03  
GeneralRe: Point #2sussAnonymous8:29 21 Oct '03  
GeneralRe: Point #2memberMichael P Butler8:41 21 Oct '03  
GeneralRe: Point #2memberKevin McFarlane1:13 28 Oct '03  
GeneralRe: Point #2memberdanitrol21:54 28 Oct '03  
GeneralRe: Point #2memberPit M.23:46 21 Oct '03  
GeneralRe: Point #2memberArnaud Brejeon0:41 22 Oct '03  
GeneralRe: Point #2memberKevin McFarlane1:25 28 Oct '03  
GeneralRe: Point #2memberjhwurmbach22:14 29 Oct '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 20 Oct 2003
Editor: Smitha Vijayan
Copyright 2002 by Duncan Edwards Jones
Everything else Copyright © CodeProject, 1999-2008
Web16 | Advertise on the Code Project