XRDS

Crossroads The ACM Magazine for Students

Sign In

Association for Computing Machinery

Magazine: Advice Five programming tips

Five programming tips

By ,

Full text also available in the ACM Digital Library as PDF | HTML | Digital Edition

Tags: General

back to top 

During college, your course instructors might not be teaching you industry-standard programming techniques. While ad-hoc coding may be acceptable for an assignment that you'll never look at again, coding practice throughout industry is typically highly regimented. It's that way entirely out of necessity. Companies may have legacy (gasp COBOL!) code older than you. This code has likely changed hands dozens of times and needs to be understood by anyone who touches it.

Follow these five tips to keep your code organized and understandable.

Comment often. You should comment each significant block of code you write—even more, if your heuristics may be difficult to follow. Try to keep your comments consistent, concise, and clear. Whether you use double slashes or semi-colons, keep the same formatting throughout.

Format code consistently. Be consistent with formatting. Do you indent with four spaces or with a tab character? Check with a manager or supervisor to see if there's a set standard within the company. No matter what method you choose, keep it consistent. Pay attention to other people's formatting conventions, too, and see if there is anything to be learned by reading between the lines.


"Working on code is very often a team effort, so always think about who else will have to deciper it, correct it, or change it."


Use one naming convention. Stick to one naming convention and use it all the way through. 'Int1' does not convey much information and can be easily confused. Use descriptive names to convey what will be contained in the variable. Append a few letters to describe the variable type: 'Int1' could become 'intTotalCost.' Again, check with a supervisor or colleague to find out of there is a preferred naming convention used in your company or division.

Avoid globals. Avoid globals if possible. No really, they are more hassle than they are worth.

Fail gracefully. Check return values from functions to help spot errors. Report any errors with as much detail as possible. This makes debugging much easier.

Perfection is impossible. However, with proper documentation and consistency, others should be able to read and decipher your code for future work. Remember that working on code is very often a team effort, so you want to always think about who else will have to decipher your code, correct it, or change it.

These five simple and commonsense suggestions are probably the most beneficial ways to improve your code and its associated documentation quickly and get you off on the right foot at a new job or in working with a new team. Happy coding!
        —Jason Thibodeau

back to top  Footnotes

DOI: http://doi.acm.org/10.1145/1836543.1836548

back to top 

©2010 ACM  1528-4972/10/0900  $10.00

Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee.

The Digital Library is published by the Association for Computing Machinery. Copyright © 2010 ACM, Inc.

Comments

Thu, 26 Aug 2010 07:57:20 UTC

Post by Sasidhar Kasturi

Good work Jason. These probably are the first 10 sentences in a programmer's bible.

My two cents: 1. With the usage of IDEs, indentation is being taken care of in a way. Once a template is set at the organizational level, the ide takes care of the rest. Languages like python help in a way, as they divide blocks based on the indentation that we provide. So, the programmer is indeed forced to indent, for putting his logic down into code. 2. Many languages now don't have a restriction(realistic) on the number of characters one can use for a variable name. And with technologies like IntelliSense in IDEs, the pain of typing in large variable names is also lessened. So it might be better in cases to declare variables of the length of a sentence(though the code looks a bit unclean). 3. In case one really needs some global variables, ts better to add some indication of what kind of variable it is (global, local) etc in its name. In C conventionally, capital letters are used for global variables. And in python, we need to explicitly write "global" when we are trying to access a global variable.

Overall, its better to start using an IDE(eclipse, visual studio etc .. ) for programming. Some of the best practices(comments, indentation) implicitly get into one's mind while programming. Also, it is easier to undo mistakes like, renaming variables after 1000 lines of code are written.

-Sasidhar Kasturi.

 

To comment you must create or log in with your ACM account.

Pointers

ACM Journal on Educational Resources in Computing (JERIC)

JERIC is an electronic publication providing access to high quality, archival resources suitable for use in support of computing education
http://jeric.acm.org

ACM Special Interest Group on Ada Programming Language

Forum on all aspects of the Ada language and technologies
http://www.sigada.org/

ACM Transactions on Multimedia Computing, Communications, and Applications (TOMCCAP)

TOMCCAP focuses on multimedia computing, multimedia communications, end-to-end streaming media, resource allocation, multicast protocols, and multimedia applications
http://tomccap.acm.org

ACM Transactions on Programming Languages and Systems (TOPLAS)

The purpose of TOPLAS is to present research results on all aspects of the design, definition, implementation, and use of programming languages and programming systems
http://userweb.cs.utexas.edu/~toplas

ACM Transactions on Software Engineering and Methodology (TOSEM)

Designing and building a large, complex software system is a tremendous challenge. TOSEM publishes papers on all aspects of that challenge
http://tosem.acm.org

Journal of the ACM (JACM)

JACM aims to provide coverage of the most significant work going on in computer science, broadly construed
http://jacm.acm.org