New Perspectives On Web Design

(C. Jardin) #1

CHAPTER 2 Writing Maintainable, Future-Friendly Code


you used an IDE like Visual Studio to learn coding, your style probably
matches the one enforced by the editor. If you learned using a plain text
editor, your style likely evolved from what you thought was more readable.
You may even notice that your style changes from language to language.
The decisions that you made in JavaScript might not carry over to your
CSS. For instance, you might decide JavaScript strings should use double
quotes while in CSS strings should use single quotes. This isn’t uncommon
as we tend to switch context when we move back and forth between lan-
guages. Still, it’s an interesting exercise in self-observation.
Coding style is made up of numerous small decisions based on the
language:


  • How and when to use comments,

  • Tabs or spaces for indentation (and how many spaces),

  • Appropriate use of white space,

  • Proper naming of variables and functions,

  • Code grouping an organization,

  • Patterns to be used and patterns to be avoided.


This is by no means an exhaustive list, as coding style can be both
extremely fine-grained, such as the Google JavaScript Style Guide^1 , or more
general, such as the jQuery Core Style Guidelines^2.

iT’S PeRSonal
The personal nature of coding style is a challenge in a team atmosphere.
Often, seeking to avoid lengthy arguments, teams defer creating style
guides under the guise of not wanting to discourage innovation and
expression. Some see team-defined style guides as a way of forcing all
developers to be the same.

1 http://smashed.by/javascriptguide
2 http://smashed.by/jqueryguide
Free download pdf