New Perspectives On Web Design

(C. Jardin) #1
By Nicholas Zakas CHAPTER 2


  • Works temporarily: the code works only so long as some unrelated
    factor remains true (such as browser version).

  • Each change requires touching multiple files: whenever you want
    to make a change, you need to touch multiple files, which increases
    the likelihood of introducing errors.


Each of these has a ‘code smell’, something that makes the code you’re
working with quite unpleasant and is an indicator that something is
wrong. Fortunately, you can start making such code easier to deal with by
applying some good practices as you continue working with it.


Code Conventions
When I was studying computer science in college, I had one extremely
tough professor. His name was Dr. Maxey and he taught the more com-
plicated courses like data structures and computer architecture. He was a
wonderful teacher with a talent for articulating difficult concepts, but also
an extremely tough grader. Not only would he look over your code to make
sure that it worked, he would subtract points for stylistic issues. If your
code lacked appropriate comments, or even if comments contained a mis-
spelled word or two, he would deduct points. If your code was messy (by
his standards), he would deduct points. The message was clear: the quality
of your code is not just in its execution but also in its appearance. That was
my first experience with coding style.


whaT’S a STYle anYwaY?


Coding style is how your code looks, plain and simple. And by “your” I
actually mean the code written by you, the person reading this chapter.
Coding style is extremely personal and everyone has their own preferred
approach. You can discover your own personal style by looking back over
code that you’ve written when you didn’t have a style guide to adhere to.
Everyone has their own style because of the way they learned to code. If

Free download pdf