Writing Code That Is Easily Understood

Recording a simple macro here or there might not seem much like programming, but after you start creating them by hand, recording and editing more complex macros, or even writing what amount to full-fledged computer programs, some general principles of software development become more important. One of these principles is using a consistent system of coding conventions.

Coding conventions result in code that is self-documenting, which is to say, written in such a way that it describes what it is and what it's used for. Different aspects of self-documenting code can be accomplished through several methods, some of which have been touched on earlier in this chapter:

• Naming conventions

• Constants for procedures and variables

• Explicit declarations

• Named arguments

• Modularized code

• Formatted code

You know that your coding conventions work when someone unfamiliar with your code can rely upon the code itself to "explain" what procedures do, what type of data they accept or return, which variables have local or global scope, and so on.

Tip Use comments

Use comments liberally throughout your code. Strictly speaking, of course, comments have nothing to do with self-documenting code, but they are used to make your code as readable and easy to understand as possible.

Comments in Visual Basic begin with an apostrophe ('). Anything that comes after the comment character, even if it's in the middle of a line of code, is considered a comment and is ignored by Visual Basic. (An apostrophe that is inside a set of quotation marks is not treated as a comment character.)

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment