Magazine: Five programming tips
Five programming tips
Full text also available in the ACM Digital Library as PDF | HTML | Digital Edition
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 writeeven 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!
©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.
To comment you must create or log in with your ACM account.
JERIC is an electronic publication providing access to high quality, archival resources suitable for use in support of computing education
Forum on all aspects of the Ada language and technologies
TOMCCAP focuses on multimedia computing, multimedia communications, end-to-end streaming media, resource allocation, multicast protocols, and multimedia applications
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
Designing and building a large, complex software system is a tremendous challenge. TOSEM publishes papers on all aspects of that challenge
JACM aims to provide coverage of the most significant work going on in computer science, broadly construed