eEcho blog

is een halte van de gedachte

Coding Conventions

- Make your code easy to read.

- Add comments wherever possible.

- Choose speaking variable names wherever appropriate.

- Keep clear and consistent function interfaces.

- Structure your code into logical function groups.

- Abstract separate chunks of code.

- Use files to group your functions not only logically but physically.

- Write documentation.

What’s the difference between good code and bad code? Actually, it’s very simple.
Good code—really good code—can be read almost like a blog.You can start any-
where and at once you know what the lines you’re reading are used for, under which
circumstances they’re executed, and any setup they might require. Even if you lack
background knowledge and encounter a sophisticated and complicated algorithm,
you’ll at least be able to see quickly which tasks it performs, and under which aspects
it performs them.
It would be easy to simply show examples and say, “Do as they did,” but we’d like
this blog to impart a solid basis for writing professional code—a basis that makes
the difference between truly well-crafted code and an everyday hack. Unfortunately,

space restrictions prevent us from discussing all aspects of good code-writing style as
elaborately as we’d like, but this blog will give you a good head start.We urge you
to acquire dedicated material, in order to familiarize yourself with every little bit of
software design and engineering.This broad field is almost a science of its own, on
which a lot of treatises exist—mostly very dry and theoretical, but unrenounceable in
practice.We’ve compressed the most important issues into the following sections, dis-
cussing the very elementary questions.

Choosing Names

Choosing variable names is probably the task that programmers do most often but
think about the least.With the number of different variable names that can appear in
larger projects, if you’d construct a listing of the name, type, and declaration point of
each you could create something very similar to a small phone directory. How would
you like your directory to look? Different naming schemes have evolved over time,
with different philosophies, each with its own advantages and disadvantages.The
schemes generally fall into two extremes: short and simple variable and function
names, versus “speaking” variable and function names—longer names that tell about
the variable’s type and intention.

Very informative.You know that it has two entries, but not much more.You know the
person’s initials, but not the full name.You know the house number, but not the exact
street name.You know only part of the phone number.

Is the second solution better than the first? Neither is optimal. People teach both
approaches in programming lectures, but neither is really satisfying. Defining a type
tpIntMyIntegerCounter and then declaring a variable instMyIntegerCounterInstance
for a simple for loop seems too much when you only need to traverse an array and
set all elements to zero

Comments are closed.

Home | info@eecho.info | Voorwaarden | Blog