Since writing On Coding Standards and Code Reviews, several people have asked me:
- Is it worth it to have a coding standard and to perform code reviews?
After all, you pay an opportunity cost in that time and energy spent on these
activities might be better spent elsewhere.
I should have thought about this earlier because it would have helped
focus our coding standard effort on tangible business benefits.
To remedy that oversight, I list below what I see as sound reasons
for having a coding standard and for performing code reviews.
I'm posting my notes here to gain some useful early feedback.
Why Have a Coding Standard?
Successful software tends to live a long time: bugs are fixed;
new features are added; new platforms supported; and the software
adapted to new markets.
That is, successful software development is a long term activity.
If you plan to be successful, you should therefore plan for your code base to be
maintained by a succession of many different programmers over a period of many years.
Not planning for that is planning to fail.
This is the primary reason why you want a company coding standard:
to make long term code maintenance easier.
Notice that if you choose instead not to mandate a coding standard, you'll likely
end up with an informal one anyway, as some strong personality in your organisation
fills the vacuum by evangelizing their own set of pet coding rules.
The goals of a good coding standard are:
- Improved code maintainability.
- Improved code quality. In particular: testability, supportability, portability, security, efficiency, robustness, high cohesion/loose coupling.
- Improved development speed. Your developers don't need to make all decisions starting from first principles.
- Better teamwork. Don't waste time with needless debates. Spend your creative energy on things that matter.
- Make it quicker and easier for a developer to move to a different project or team.
- Better performance under pressure. Under stress, people fall back on what they've been trained to do.
- Fewer bugs. Good standards should minimize common coding mistakes.
- Shallower learning curve and useful training for new hires -- if your standard mandates proven, well-known idioms and style from the programming mainstream.
- Higher company IP value.
- The coding standard should be something developers learn from, want to follow, and want to contribute to; it should make their lives easier, not harder.
- The coding standard should be a living document; you need a mechanism for evolving it and for dealing with the millions of lines of old code that are affected by changes to it.
The above list represents real business benefits which should help you decide
what to put in your coding standard and what to leave out.
My experience here is that shorter is definitely better. The longer your coding
standard document, the less likely that it will be read, understood and followed.
Why Perform Code Reviews?
- Find and fix defects early.
- Code review often proves more cost effective than testing. (See, for example, The Case for Peer Review).
- Good mentoring/training/learning/team building, especially for new hires.
- Gives broader experience to team members.
- Makes it easier for one team member to maintain another's code.
- Improve overall quality of the code.
- Enforce coding standards.
Of course, code reviews are not free and there is an opportunity cost
in that time spent reviewing code means less time spent on other activities.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||