Coding standards 101

ANALYSIS
Coding standards increase productivity in the development process, make code easier to maintain, and keep code from being tied to one person or team. But where should standards come from? How extensive should they be, and more importantly, who should enforce them? Here are the short answers to these questions. Who dictates the coding standards?
You can choose from many industry coding standards. Some companies -- Microsoft and Sun Microsystems, for example -- offer guidelines. Some coding standards, such as Hungarian Notation, are the product of one person's labour (in this case, Dr. Charles Simonyi, a Hungarian software developer at Microsoft). Certain coding standards are language specific. Standards for Visual Basic dictate that you should prefix all textboxes with "txt" and all buttons with "cmd." Sun Microsystems offers coding standards for Java. Once you've settled on a coding standard, take the language-specific suggestions and add your own. For example, you might decree that variable and function names should be descriptive, or that the behavior of particular functions must be clearly commented. (My mantra is "Document, document, document: every class, every method, every few lines of code.") How extensive should coding standards be?
While it's important to have coding standards, it's equally important not to have superfluous coding standards. Imagine, if you will, a standard that dictates that the first character of a variable name must indicate the application in which it resides, the second character must indicate the module, and the third character must indicate the data type. Excessive coding standards such as this can impede the creative process and become a hindrance to development. You should not have more coding standards than will fit on one or two pages. It makes it very hard to name your variable if you have to consult a chart to do so. Who enforces coding standards?
I've worked in many software shops where coding standards existed, but no one enforced them. The result: The coding standards were about as effective as the "Do you come here often?" pickup line. The first step in enforcing coding standards is to keep those standards easily accessible. Ideally, you should have a laminated cheat sheet pinned up in each developer's cube. During peer code review sessions, someone's job must include being code standards bad cop. However, automated tools offer another option to managers looking to enforce standards. Some of the best tools on the market are made by Parasoft. Parasoft produces language-specific tools that automatically enforce more than 300 coding standards. The products include a RuleWizard feature, which allows developers to create and implement their own custom rules. One of the standards enforced by Parasoft products requires that one-character variable names be used only for their conventional purpose, such as b for a byte, c for a char, f for a float. If this standard is violated, the output would look like this:
package examples.rules.naming;
 
 public class CVN {
     void method () {
         int b = 1;  // VIOLATION
     }
 }
Conclusion
Coding standards are a must for any development team. They ensure consistency and simplify the maintenance process with legible code. Your job is to make sure a standard is chosen, strictly followed, and always on the developer's mind.

Have your say instantly in the Tech Update forum. Find out what's where in the new Tech Update with our Guided Tour. Let the editors know what you think in the Mailroom.

Post your comment

In order to post a comment you need to be registered and logged in.

You can also log in with Facebook. Log in or create your ZDNet UK account below

  • Login

Will not be displayed with your comment

By signing up for this service, you indicate that you agree to our Terms and Conditions and have read and understood our Privacy Policy. Questions about membership? Find the answers in the Community FAQ

Get ZDNet UK's daily newsletter

Enter your email address to sign up

ZDNet UK Live

Moley

For Gnome 2 die-hards, it is possible to add icons to the bottom panel (or top top panel, if you prefer) which provide the exact Gnome 2...

28 minutes ago by Moley on A tale of two distros: Ubuntu and Linux Mint
ramwellian

Your comments would seem pretty naive and immature. Your 'solution' appears to be, "gee, let's all just give in to the hackers and give them...

41 minutes ago by ramwellian on Cloud computing security: no more oxymoron?
BugStalker

"Interesting thought ... If you installed Win7 as a dual boot on a machine that previously only had Linux, and it wrecked your Linux installation,...

60 minutes ago by BugStalker on Windows 7 Declares War on GRUB
whs001

This is an excellent summary of Ubuntu and Mint and the interface differences between them. Most such articles take a very partisan position for...

1 hour ago by whs001 on A tale of two distros: Ubuntu and Linux Mint
Moley

@ewallace. Not so clear. Anyone can obtain the text, for example from here http://www.ustr.gov/webfm_send/2379. I support ACTA so long as it and...

1 hour ago by Moley on ACTA: Facts, misconceptions and questions
45283

I think WinRT is fantastic. I just wish it was an option for people that didn't want to go through Microsoft's App Store with its attendant...

4 hours ago by 45283 on Why Windows 8 needs architectural hygiene for WOA
Burn-IT

Nine people? £30m? Who's back pocket is that lot going in? And IF they say it is for new buildings, what about all the ones the government has...

6 hours ago by Burn-IT on Police set to launch three £30m e-crime hubs
ewallace

Just to be clear, nobody knows what is in the text of ACTA, here is a photograph of the text of ACTA http://twitpic.com/8h9iju as submitted to the...

6 hours ago by ewallace on ACTA: Facts, misconceptions and questions
fgvrg56

Unfortunately main issue is that ASUS is refusing to accept that they make some mistake on this version of asus Transformer prime. 1 - GPS sensor...

7 hours ago by fgvrg56 on Asus Eee Pad Transformer Prime Wi-Fi & GPS problems?
Ben Woods

@Marcus A fair question. Just talked with Archos which said it was working on an announcement for next week....

8 hours ago by Ben Woods on Archos confirms G9 Ice Cream Sandwich update schedule

Any update on this, considering the claimed "first week of February"?

9 hours ago by via Facebook on Archos confirms G9 Ice Cream Sandwich update schedule
apexwm

Bill Goodrich : Just as al_langevin pointed out, with Windows Server 2008 there is no Services for Macintosh anymore. It's gone, not available....

17 hours ago by apexwm on Windows Server 2008 drops the ball for Mac compatibility
txtrainguy

Replying to an old topic that I'm currently facing with my CEO (who is on a Mac). Our servers are primarily Windows Servers, office is about...

24 hours ago by txtrainguy on Windows Server 2008 drops the ball for Mac compatibility
k0tcs3

Sure, that makes perfect sense. Pay wrong-doers money and thank them for breaching your security and pointing out your flaws, that would surely...

1 day ago by k0tcs3 on US indicts Romanian over NASA climate change hack
Random_Error

I think he's referring specifically to Android apps, as Apple do regulate their App Store, but Google seem to let any old crap onto the Android store!

1 day ago by Random_Error on RIM: BlackBerry will keep 'garbage' apps out of store
Paul Fezziwig

Keep the crap apps out?! How will they compete with Android and Apple's claim to fame of having so many life changing apps? I wonder if the media...

1 day ago by Paul Fezziwig via Facebook on RIM: BlackBerry will keep 'garbage' apps out of store
Aigars Mahinovs

It has been shown time after time that if there is an author store that sells the songs at even 1$ per song and gives you a high-quality digital...

1 day ago by Aigars Mahinovs via Facebook on Copyright isn't working, says European Commission
awbMaven

""As a result of Butyka's alleged conduct, researchers were unable to use the computers for more than two months while NASA removed the malicious...

1 day ago by awbMaven on US indicts Romanian over NASA climate change hack
subhorup

It simultaneously worries me and uplifts me that a self-proclaimed group of internet activists name themselves after Indian mythical figures....

2 days ago by subhorup on Anonymous activists release PCAnywhere source code
naviathan

It's actually far easier to work anonymously on the internet than you think. With tools like Tor bouncing your traffic around the world before...

2 days ago by naviathan on Anonymous activists release PCAnywhere source code

Latest in Application Development