New Perspectives On Web Design

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

code: not enough tests, too little documentation, patterns that make no
sense. Then, solve those problems as you write the new code.


Conclusion
This entire chapter covers the specific steps you can take to make sure
code you write is as maintainable and future-friendly as possible. The
best way to avoid spaghetti code is to put the work in up front to organize
things. Code conventions ensure that everyone speaks the same language.
An architecture lays a solid foundation on which to build. Good documen-
tation is important so others can extend your code later. Choosing and
managing third-party components appropriately makes sure you have a
linear upgrade path as fixes become available.
Of course, it’s not every day that you start out with a blank slate. You’ll
deal with someone else’s code quite frequently. If that code falls into the
category of legacy code, then your path forward is to make small pieces of
that code easier to understand every day. Add documentation. Add tests.
Don’t believe in magic.
A codebase takes on a life of its own over time. Some grow to be elegant
and beautiful while others grow to be gnarly and stinky. Exactly how your
codebase grows depends on how you nurture it, the structure you give it,
and how comfortable people are with making modifications.

Free download pdf