INTRODUCTION
WHAT ARE CODING CONVETIONS?
Coding conventions are a set of guidelines one or more
programmers use to aid in the difficult task of writing consistent code
with "good" style. No matter what particular task the code is
supposed to accomplish, coding conventions are designed to help a programmer
most easily and effectively translate the ideas in his head into whatever
particular programming language he might be using. Coding conventions usually
address such issues as: general code layout, naming of constants, variables,
functions, etc., simulation of control and data structures not directly
offered by the particular language being used, avoidance of dangerous coding
practices which the given language does not restrict against, and work-arounds
for design tool bugs.
WHY SHOULD THEY BE USED?
Just from reading the definition given above one can already
begin to get a feel for some of the benefits of coding conventions; one
really cannot even give a satisfactory definition of them without hinting
at their great usefulness. It turns out that not only are coding conventions
a great means for a programmer to practice abstraction (his best friend)
and combat complexity (his worst enemy), they actually become an absolute
necessity for projects containing a high level of complexity. Here are
a few of the many benefits of coding conventions:
- Improved readability, a tool of abstraction which
allows a programmer to turn his attention away from always trying to figure
out exactly what his code is "saying" and instead concentrate
on whether what he is "saying" will accomplish the goal he wants
it to. Not only does this make the coding process easier, but it will open
the door from him to help from his peers. Try showing code with poor readability
to a friend (or TA) and ask for help and you can expect an answer
like, "Uhh...maybe later...I’m pretty busy right now...", meaning
there is no chance that the person is going to waste his time trying to
understand your archaic code. On the other hand, if you go that extra mile
to make your code easy to understand, you’ll suddenly find yourself surrounded
by friends very willing to help you out; not only does it minimize the
inconvenience for them, but it greatly increases the chance that they will
even learn something from you which will help them in their own work.
- Coding becomes...dare we say it..."easy".
Assuming you first write out your code in PDL (program design language:
a mixture of English and control structures that is at a higher level of
abstraction than any programming language), which you should always do,
coding is really nothing more than translating your PDL into a language
your compiler can understand. But this is exactly what code conventions
do for you: they tell you exactly how to turn your thoughts into the programming
language you’re working with, thus the coding process suddenly becomes
a simple, mechanical process: a no-brainer.
- They explain how to overcome the inherent weaknesses
of the particular language you are working with. If the language you’re
working with does not support a particular control or data structure available
in other languages, code conventions explain how to overcome this deficit
by utilizing the structures which are available to simulate the ones which
are not. In addition, if the language you are working in allows programming
practices which you know are dangerous, code conventions can protect against
those pitfalls from the project’s very outset and act like a safety net
that saves you before you ever fall into danger.
- Once created, they stand as a resource for the lifetime
of the language. If you ever forget what the exact syntax is for something
or how to overcome an inherent weakness in the language you are using,
the conventions stand as a ready resource so that time does not need to
be wasted later on looking for answers you already spent the time to find
when you first started using the language.
- They outline how to overcome design tool bugs.
If you know your compiler consistently mistranslates or just flat-out crashes
whenever it sees a particular piece of code, coding conventions can be
used to outline a standard work-around so that the bug need not hinder
your work.
- They make multiperson projects possible by homogenizing
code. Everybody’s code looks the same and therefore makes it easy for
anyone to understand and modify anyone else’s work. It also emphasizes
the idea that all code written is public property rather than private,
opening the code up to improvement without anyone becoming sensitive about
criticism of "their" code.
- Once you are know a project’s coding conventions,
you will already have a level a familiarity with it before even you see
its code for the first time. This minimizes the overhead involved with
beginning work on an existing project by making learning new code a much
quicker and easier process.
- It makes maintenance possible. In the "real
world", often large amounts of code will be maintained and updated
by only a few people who were not members of the project’s creation team,
hence it becomes an economic necessity for companies to have their code
be very "learnable" and revisable.
- You will have to use them in the real world, so might
as well get used to working with them now. As stated earlier, any medium
to large-sized project is impossible without coding conventions, so it
is almost certain that any programming you do after college will require
that you use them; take the time now and learn how to make the most of
them. Believe it or not, this skill is highly valued in the working world
and will make you a greater asset to your future employer.