    <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  :: Taking the Easy Road</title>
        <link>https://members.accu.org/index.php/journals/988</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>


        <h2>Journal Articles</h2>


<div class="xar-mod-head"><span class="xar-mod-title">CVu Journal Vol 12, #2 - Mar 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/journals/">All</a>

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

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

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c127/">122</a>
                    (18)
<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;Taking the Easy Road</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 March 2000 13:15:36 +00:00 or Fri, 03 March 2000 13:15:36 +00:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e20" id="d0e20"></a></h2>
</div>
<p>The recent interview with Kent Beck about Extreme Programming
(XP), in Overload 35, was not my first exposure to its practices. I
stumbled across the Wiki site (<a href=
"http://c2.com/cgi/wiki?ExtremeProgrammingRoadmap" target=
"_top">c2.com/cgi/wiki?ExtremeProgrammingRoadmap</a>) not too long
ago, and instantly recognised that I could make use of at least
some of the practices advocated there.</p>
<p>One thing immediately stood out from the page which I found
difficult to rationalise; &quot;You Aren't Gonna Need It&quot; is (or seems
to me to be) a cornerstone of the XP discipline, and describes the
situation where you foresee a possible feature or use which is not
immediately required but may be in some indeterminate future. 'You
Aren't Gonna Need It' says, well, do not do it.</p>
<p>I first thought of &quot;feature creep&trade;&quot;, thereby justifying it
to myself. More thought placed me in a quandary, however. I had
recently read the <i class="citetitle">Effective/More Effective
C++</i> CD by Scott Meyers. I am a self-confessed learner (I hope I
never stop being one) and admit to being heavily influenced by
Scott's books. Hence, I recalled the axiom &quot;Program in the future
tense&quot; (More Effective C++) and perceived a paradox. On the one
hand I am advised not to provide for a possible future requirement,
and on the other, I am advised exactly the opposite.</p>
<p>(OK so I take Scott's words to extremes here, no pun intended,
but to me programming for the future suggests at least making
allowances for possible future expansion at the cost of spending
more time today).</p>
<p>As luck would have it, I was considering a problem which brought
these two philosophies into conflict. I had a requirement to
develop a program which, in essence, read a file in a certain
format and produced a new file in a different format. As with
perhaps all such programs (and many others) it was needed the
day-before-the-day-before, and so the aforementioned facet of XP
reared its head above my shoulder. As I set about producing a basic
design, an image of a CD with &quot;More Effective C++&quot; written on it
appeared above my other shoulder.</p>
<p>For peace and quiet, I wanted to reconcile these two opposing
views, and meet my deadline (revised to &quot;tomorrow&quot; ;-)).</p>
<p>The rules for the program were very strict - making for a great
specification and simple design:</p>
<div class="orderedlist">
<ol type="1">
<li>
<p>Read a text file in fixed width format</p>
</li>
<li>
<p>Find each record where a certain field contains a certain
sequence of characters</p>
</li>
<li>
<p>Write matching records to a new file in comma separated
format</p>
</li>
</ol>
</div>
<p>Such problems may be the stuff of student &quot;Introduction to
Programming&quot; assignments, but they are also my daily bread. My
initial design consisted of little more than the bullets above. A
little further thought revealed a flaw, however. I guess you've all
spotted it by now: what if the input format changes? And from this
question, others arose: what about the output format? The record
selection rule? The record layout?</p>
<p>XP said &quot;don't worry about it - You Aren't Gonna Need It (and if
you do, handle it then).&quot;</p>
<p>Scott said &quot;You are gonna need it. Face it, it will change. It's
inevitable.&quot;</p>
<p>Part of the rationale behind XP's thoughts on this are to
prevent feature creep and to help prevent the programmer getting
distracted from the current requirements. Being easily distracted,
it seemed a good idea to me, not to mention being lazy, i.e. don't
write anything you don't have to.</p>
<p>However, I also wanted to ensure that my program could be
graceful in the event of change, and I believe Scott Meyers when he
tells me it's inevitable. I've had to maintain and modify enough
programs to understand that.</p>
<p>In the end, it was the Gang of Four who came to my rescue. Enter
the Strategy. This is a pattern I first encountered in <i class=
"citetitle">Design Patterns - Elements of Re-Usable Software</i>
[Gamma, et. al.1995]. &quot;Strategy lets [an] algorithm vary
independently from the clients that use it.&quot; It occurred to me that
I could use this technique to provide an algorithm for each part of
the problem, and that they could be changed easily in the future to
accommodate different requirements. It also means that I don't have
to write a large amount of code that XP says I won't use, and so
won't get led off the beaten track of the initial
specification.</p>
<p>The details were fantastically simple. Each of the four basic
procedures was defined by a base class:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>File Reader</p>
</li>
<li>
<p>Record Layout</p>
</li>
<li>
<p>Record Selector</p>
</li>
<li>
<p>File Writer</p>
</li>
</ul>
</div>
<p>I made these abstract so they provided the interface and no
more.</p>
<p>Each abstract operation is made concrete by a derived class. In
the initial requirements there is only one concrete implementation
for each procedure, but it means that the principle is extendible
independently of the other procedures:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>Fixed Width Reader</p>
</li>
<li>
<p>(This File type) Record Layout</p>
</li>
<li>
<p>(This Selection Rule) Record Selector</p>
</li>
<li>
<p>CSV Writer</p>
</li>
</ul>
</div>
<p>So, to change the format of the output file to a spreadsheet
format, a new class inherits from the File Writer base class, and
defines the operations its own way. None of the other operations
need to even know about the modifications. Similarly, changes can
be made to the internals of one concrete class, which will (should)
be invisible to the other classes. More importantly, such changes
are transparent to the clients of these classes.</p>
<p>Moreover, it is possible to change the behaviour of the program
dynamically, perhaps via a menu. All that would be required are
declarations of the required operations. The strategy for each
operation could be a class member (held as a pointer to the base
class) or a global/namespace scope variable.</p>
<p>With the overhead of describing a base class and a single
concrete class for each operation, we have nearly abided by the XP
rule of &quot;You Aren't Gonna Need It&quot; but not entirely. However, the
overhead is minimal, and means that we have completely abided by
the axiom of programming for the future. As compromises go, I think
it pleased both parties considerably.</p>
<p>Finally, the program was delivered within the time scale. Even
my student &quot;Introduction to Programming&quot; assignments didn't always
enjoy such treatment.</p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
