    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Professionalism in programming Part 4</title>
        <link>https://members.accu.org/index.php/articles/1061</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Professionalism in Programming, from CVu journal + CVu Journal Vol 12, #5 - Sep 2000</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c184/">Journal Columns</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c182/">Professionalism</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c124/">125</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c182-124/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c182+124/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Professionalism in programming Part 4</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 06 September 2000 13:15:40 +01:00 or Wed, 06 September 2000 13:15:40 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e22" id="d0e22"></a></h2>
</div>
<p>How do you learn to be a good carpenter? You become an
apprentice to someone. You watch how they ply their trade, and
listen to their advice as they watch you work. You do not jump in
feet first without any practical ability and expect to be able to
churn out quality furniture straight away. We do not have an
analogue of that in the coding world, even though it is about as
much a craft as it is an engineering discipline.</p>
<p>Code reviews, however, do give us a little bit of that in the
discipline of an engineering process. I hope that does not put you
off - really!</p>
<p>Performing code reviews in a software company is similar in some
ways to the model of open source software development. By
performing reviews, you encourage responsibility for what you are
coding. When you know that your code is not just for you to look
at, but it will be viewed, used, maintained and criticised by
others your approach tends to change. It prevents you making that
'quick change that you'll fix later' that in your heart you know
you will never have time to come back to. The accountability
brought on by code review brings a higher quality to coding.</p>
<p>Code reviews are used in traditional software engineering
models. They are arguably less important when pair programming, or
more than one person is responsible for parts of the code.
Nonetheless, they are still useful in these situations.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e32" id="d0e32"></a>What are
they?</h2>
</div>
<p>As C/C++/Java programmers, we write code. At the lowest level,
we are merely writing declarations, definitions and statements.
From these syntactic constructs, we form some kind of semantics in
each block of code. At some higher level, we have implemented a
particular design by expressing it in this code.</p>
<p>The code review seeks to analyse the section of written code at
several levels - the actual design, the expression of that design
in the code, and even each individual statement to ensure its
correctness. The aim of this analysis is to improve the code,
largely by finding and removing faults.</p>
<p>According to Humphrey, &quot;<span class="quote">Students and
engineers typically inject 1 to 3 defects per hour during design
and 5 to 8 defects when writing code. They only remove about 2 to 4
defects per hour in testing but find 6 to 12 per hour during code
review</span>&quot; [<a href="#PSP">PSP</a>]. Code reviews are a
worthwhile activity!</p>
<p>A code review should not take the place of the code's functional
specification review. The code is checked to conform to its
functional specification, but the content of the functional
specification is taken to be correct. If it were not then the task
would be Herculean!</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e49" id="d0e49"></a>Why do you do
them?</h2>
</div>
<p>We need to be confident about the quality of our programming,
and need to find faults as early as possible in the development
process. The earlier we try to find problems, the more we are
likely to find and fix.</p>
<p>So we perform code reviews to improve code quality. This
includes:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>removing coding errors,</p>
</li>
<li>
<p>removing redundant code,</p>
</li>
<li>
<p>ensuring efficient<sup>[<a name="d0e66" href="#ftn.d0e66" id=
"d0e66">1</a>]</sup> algorithms are used</p>
</li>
</ul>
</div>
<p>In doing this we also check the code against a number of
yardsticks, which may include:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>the specification for the work,</p>
</li>
<li>
<p>any company coding standards,</p>
</li>
<li>
<p>the appropriate language idioms (e.g. ratify the use of design
patterns)</p>
</li>
</ul>
</div>
<p>Apart from the obvious benefits that come out of this there are
other useful side-effects of code reviews. The cross fertilisation
that comes from getting programmers to look at each other's code
ensures that the coding style is more uniform across the whole
company. It also spreads knowledge about the workings of particular
bits of code, so there is less risk of loosing information when
people leave.</p>
<p>Many people shy away from a code review for fear it will expose
their inadequacies. We should not do this. Having your code
reviewed is a good way to learn new techniques. You must be humble
enough to admit that you are not perfect and willing to accept
criticism from others. A programmer's coding style will improve as
they learn from the changes made to their work.</p>
<p>This also means that when criticising code in a review, we must
be sensitive. It is interesting that even the least experienced
programmer will usually have something worth mentioning in a code
review. Moreover, just as the author learns from the review, so may
a reviewer.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e88" id="d0e88"></a>When do you do
them?</h2>
</div>
<p>In the ideal world every bit of code written is reviewed
carefully prior to release. According to the Software Engineering
Institute at the Carneige Mellon University, a thorough code review
should take at least 50% or more of coding time [<a href=
"#SQP">SQP</a>] (although they do include 'personal' code review in
this statistic).</p>
<p>If we do not have time to review every bit of code, how do we
decide whether to review and what bits of code to review? To put is
bluntly, you would be stupid not to perform code reviews at
all<sup>[<a name="d0e98" href="#ftn.d0e98" id="d0e98">2</a>]</sup>.
Compare it with product testing. You would be stupid not to test a
product prior to release. The code review tends to weed out
redundancy and bad design more than incorrect behaviour, but
certain inexplicable 'features' would be weeded out at this stage
which would be practically impossible do diagnose from a system
usability test.</p>
<p>Often you will hear people say 'but the code's too large to
review fully' or 'it's too complex, no one person could ever
understand it'. If a company can employ enough people to write a
large program, they can employ enough people to review it. If the
code is too complex, it desperately needs reviewing! In fact, it
probably needs something a little more drastic. Well-written code
should be easily decomposed into sections that can undergo separate
reviews.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e104" id="d0e104"></a>How do you do
them?</h2>
</div>
<p>In code reviews, we look at code under the microscope - really
aiming to criticise<sup>[<a name="d0e109" href="#ftn.d0e109" id=
"d0e109">3</a>]</sup> it. This is not to get at the programmer but
to improve the quality of the product/software the company
produces. Having a code review is not enough. In itself, it is not
going to solve all the problems. You also need to make sure that
you review <span class="emphasis"><em>properly</em></span>.</p>
<p>A code review is a formal meeting. There should be a fixed
agenda (to ensure no action is forgotten) and a defined ending (not
a time limit, as such, but a definition of exactly what bits of
code you are reviewing, and which bits you are not - it is very
easy to be woolly about this).</p>
<p>An example of a procedure for how to conduct a code review is
described below.</p>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e120" id="d0e120"></a>Where?</h3>
</div>
<p>The best place to hold a code review is in a quiet meeting room.
The reviewers should not be disturbed. There should be coffee.</p>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e125" id="d0e125"></a>When?</h3>
</div>
<p>Obviously, at a mutually convenient time. Common sense tells us
that Friday at 4 p.m. is not a good time.</p>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e130" id="d0e130"></a>Roles and
responsibilities</h3>
</div>
<p>One of the most important contributing factors to the success of
a code review is who attends. Obviously, the person(s) who wrote
the code should be there. The reviewers should be carefully picked.
For instance in a recent review at my company, the writer of a
library that was used by the author was present. He was able to
diagnose incorrect use of the library API that may have otherwise
gone undetected.</p>
<p>There should be an appropriate number of experienced software
engineers present. There should also be a representative from the
QA/testing department.</p>
<p>In addition to the <span class="bold"><b>author</b></span> and
<span class="bold"><b>reviewer</b></span> roles, there are a number
of other roles for which specific people should be assigned (note
that they can be both a reviewer and another role).</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p><span class="bold"><b>Chairman.</b></span> This person should
lead the review, and guide the discussion. They should ensure that
the conversation keeps to the point and the meeting does not get
sidetracked. Any minor issues that do not need to be discussed in
the meeting should be quickly taken off-line by the chairman.</p>
</li>
<li>
<p><span class="bold"><b>Secretary.</b></span> The secretary takes
the minutes. This means writing down all points that arise to make
sure that nothing is forgotten after the review. The secretary role
should not be fulfilled by the same person who acts as chair.</p>
</li>
</ul>
</div>
<p>Before arrival, everyone is expected to have familiarised
themselves with the code. Everyone should have read the supporting
documentation<sup>[<a name="d0e158" href="#ftn.d0e158" id=
"d0e158">4</a>]</sup> (any relevant specifications etc). Whoever
organises the meeting should point out these documents to prevent
misunderstanding.</p>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e162" id="d0e162"></a>What should you
do?</h3>
</div>
<p>The agenda for the meeting should be as follows:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>The author takes a couple of minutes (no longer!) to explain the
purpose of the code, and a little bit about its structure. It's
surprising what misunderstandings can be caught at this first
stage!</p>
</li>
<li>
<p>Structural design comments are invited. These are comments
relating to the structure of the implementation - not the actual
code at statement-level.</p>
</li>
<li>
<p>General code comments are invited. These may relate to a
consistent incorrect coding style.</p>
</li>
<li>
<p>The code is carefully stepped through a line or block at a time
to ensure correctness. Things to look out for are described
below.</p>
</li>
<li>
<p>A number of example scenarios of code usage are considered, and
the flow of control investigated, if this was not already necessary
to understand the code.</p>
</li>
<li>
<p>When the review has finished the follow-up step should be
agreed. The possible scenarios are:</p>
<div class="itemizedlist">
<ul type="circle">
<li>
<p>OK. The code is fine, no further work is necessary.</p>
</li>
<li>
<p>Rework and re-review. The code needs a lot of rework, and
another code review is deemed necessary following this.</p>
</li>
<li>
<p>Rework and verify. The code needs some rework, but another code
review meeting is unnecessary. Someone is nominated to act as
verifier and when the rework is completed, they check the work
against the recorded minutes of the code review meeting.</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<p>A reasonable deadline should be imposed for any rework (so that
the reasons for actions stay fresh in people's minds).</p>
<p>This is a general framework for a code review meeting. It's
beyond the scope of this column to describe what 'good structure'
is for a piece of code. However, there are a few elementary points
we can draw out that are worth noting. The reviewed code needs to
be:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p><span class="bold"><b>Predictable.</b></span> The code should
not be self-modifying, reply on no 'magic' default values, and not
have the possibility of infinite loops or recursion.</p>
</li>
<li>
<p><span class="bold"><b>Robust.</b></span> Wherever possible the
code should protect against detectable run time errors (divide by
zero, number out of range errors, etc). Input parameters should be
checked, for both function parameters and program input. C++ code
should be exception safe. All appropriate signals are caught.</p>
</li>
<li>
<p><span class="bold"><b>Data checking.</b></span> Bounds checking
is performed on array access, and other similarly insidious data
access errors are avoided. Multithreaded code has correct use of
mutexes. For any system/library calls the return value is always
checked.</p>
</li>
<li>
<p><span class="bold"><b>Well structured.</b></span> The
implementation design is correct. The code is easy to understand.
There is no redundant code (any obvious <span class=
"emphasis"><em>cut-and-paste</em></span> programming, for
example).</p>
</li>
<li>
<p><span class="bold"><b>Complete.</b></span> The code implements
the entire functional specification. It has been shown to have been
integrated and debugged satisfactorily. It passes all test
suites.</p>
</li>
<li>
<p><span class="bold"><b>Correct.</b></span> The code meets all
relevant standards and its requirements are met. All variables are
of the correct type (there is no chance of overflow). Comments are
accurate. For embedded platforms, code meets any memory size
requirements. There is appropriate use of libraries, and all
function parameters that are passed are correct.</p>
</li>
<li>
<p><span class="bold"><b>Maintainable.</b></span> The programmer
has been wise in their use of comments. The code is kept under
correct revision control. There is appropriate configuration
information. The code formatting meets 'house standard'.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e239" id="d0e239"></a>The use of
tools</h2>
</div>
<p>There are a number of different tools that may be useful when
performing a code review. For example, there are tools like the
McCabe toolset [<a href="#McCabe">McCabe</a>] that help trace flows
of execution, and calculate values for function 'complexity'. This
last metric is very useful when identifying which pieces of code
need reviewing as soon as possible. A visual design program may aid
in understanding the code structure and its dependencies
(particularly in object oriented languages like C++ and Java).</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e247" id=
"d0e247"></a>Conclusion</h2>
</div>
<p>Code reviews are an essential part of the software development
process. Just as an apprentice learns their trade from knowledge
passed on, code reviews spread knowledge and teach coding
capability. As more of a peer-to-peer than master-apprentice
activity, they provide a learning opportunity for author and
reviewer alike, and result in higher quality code.</p>
<p>In the light of code reviews, you should write your code bearing
in mind that it is not just for you to read. Other people must be
able to maintain it as well. Authors are accountable for the
quality of their code.</p>
<div class="bibliography">
<div class="titlepage">
<h2><a name="d0e254" id="d0e254"></a>References</h2>
</div>
<div class="bibliomixed"><a name="PSP" id="PSP"></a>
<p class="bibliomixed">[PSP] Humphrey, Watts S. <span class=
"citetitle"><i class="citetitle">Introduction to the Personal
Software Process</i></span>. Addison-Wesley, 1997. ISBN:
0201548097</p>
</div>
<div class="bibliomixed"><a name="SQP" id="SQP"></a>
<p class="bibliomixed">[SQP] Humphrey, Watts S. <span class=
"citetitle"><i class="citetitle">The Software Quality
Profile</i></span>. URL: <span class="bibliomisc"><a href=
"http://www.sei.cmu.edu/topics/publications/articles/quality-profile/old.file.html"
target=
"_top">http://www.sei.cmu.edu/topics/publications/articles/quality-profile/old.file.html</a></span></p>
</div>
<div class="bibliomixed"><a name="McCabe" id="McCabe"></a>
<p class="bibliomixed">[McCabe] McCabe and Associates. McCabe IQ.
URL: <span class="bibliomisc"><a href="http://www.mccabe.com"
target="_top">www.mccabe.com</a></span></p>
</div>
</div>
</div>
<div class="footnotes"><br>
<hr class="c3" width="100">
<div class="footnote">
<p><sup>[<a name="ftn.d0e66" href="#d0e66" id=
"ftn.d0e66">1</a>]</sup> For an appropriate definition of
'efficient' in it's context.</p>
</div>
<div class="footnote">
<p><sup>[<a name="ftn.d0e98" href="#d0e98" id=
"ftn.d0e98">2</a>]</sup> There are plenty of stupid companies out
there.</p>
</div>
<div class="footnote">
<p><sup>[<a name="ftn.d0e109" href="#d0e109" id=
"ftn.d0e109">3</a>]</sup> Sorry, verify.</p>
</div>
<div class="footnote">
<p><sup>[<a name="ftn.d0e158" href="#d0e158" id=
"ftn.d0e158">4</a>]</sup> Naturally, all supporting documentation
will have been thoroughly reviewed beforehand&hellip;</p>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
