HomePractices Page 2 - The Art Of Software Development (part 3): Coding To A Plan
The Name Game - Practices
With the design out of the way, it's time to finally sit downand write some code. This article discusses the implementation phase ofthe software cycle, outlining some ideas and techniques that should helpyou deliver cleaner, faster and more maintainable code. Miss it at yourperil!
Shakespeare famously said, "What's in a name? A rose by any other name would smell as sweet". And this is true - so long as you're talking about roses. In the world of software development, though, naming conventions and coding standards acquire significance in making your code easier to read, understand and maintain.
There are some basic rules to be kept in mind when naming objects within your application. Here's a brief list:
Choose meaningful names for your objects. "itemCode" is far more descriptive that "icd".
Capitalize the first character of each word in your chosen name, or use underscores to separate words - this makes the name easier to read.
Use names that are short and easy to pronounce.
Ensure that the name chosen is not ambiguous.
Use capitalization and/or underscores to differentiate between private and public variables, or local and global variables.
Begin function or method names with a so-called "action word" - for example, "getItem()" or "doQuery".
It's also important to decide on and follow a specific coding standard when naming your variables and functions, and to carry this convention through consistently in all your scripts. This coding standard should specify the naming conventions for variables, functions and objects, file name prefixes and suffixes, file organization rules, indentation and comment style, and comment and white space usage. Ensure that the document specifying the coding standards includes examples that illustrate each rule clearly.
Of course, having a standard by itself is fairly useless - it needs to be enforced for it to provide any real benefits. Make it a point to review the manner in which code is written during your code inspection sessions, and ensure that your development team follows the standards previously decided. This will make code review simpler and faster, and also make it easier to transition a released application to a new team for maintenance or bug fixes.
Make sure that your application filesystem is structured properly, and that the different components are all in the right place. Spend some time developing a suitable directory structure within which your application code will reside, and clearly demarcate the locations in which different bits of data are to be stored. If your application files will be named according to a specific notation, consider all cases when defining this naming convention and ensure that it covers all possible situations.
Finally, comment, comment, comment! It might seem like a drag to add comments to your code while you're developing an application, but observations have shown that comments play an important role in improving the quality of your code. Not only does a comment serve as a handy reminder of the thought process that went into a particular bit of logic, it also helps other developers read and review your code.