    <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  :: YAGNI-C as a Practical Application of YAGNI</title>
        <link>https://members.accu.org/index.php/articles/1837</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">Programming Topics + Design of applications and programs + Overload Journal #117 - October 2013</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/c13/">Topics</a>

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

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

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

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c67/">Design</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/c78/">Overload</a>

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

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

                    -                        <a href="https://members.accu.org/index.php/articles/c65+67+330/">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;YAGNI-C as a Practical Application of YAGNI</h1>
<p><strong>Author:</strong>&nbsp;Martin Moene</p>
<p>
<strong>Date:</strong> 05 October 2013 20:36:01 +01:00 or Sat, 05 October 2013 20:36:01 +01:00</p>
<p><strong>Summary:</strong>&nbsp;YAGNI can seem vague. Sergey Ignatchenko offers a more precise definition.

</p>
<p><strong>Body:</strong>&nbsp;<p class="quote">ALGOL&nbsp;68 was the first (and possibly one of the last) major language for which a full formal definition was made before it was implemented.<br />~ C.H.A. Koster</p>

<p class="quote">... as a tool for the reliable creation of sophisticated programs, the language [ALGOL&nbsp;68] was a failure ...<br />~ C.A.R. Hoare</p>

<p class="EditorIntro">Disclaimer: as usual, the opinions within this article are those of â€˜No Bugsâ€™ Bunny, and do not necessarily coincide with the opinions of the translator or the <em>Overload</em> editor. Please also keep in mind that translation difficulties from Lapine (like those described in [<a href="#[Loganberry04]">Loganberry04</a>]) might have prevented providing an exact translation. In addition, both the translators and <em>
Overload</em> expressly disclaim all responsibility from any action or inaction resulting from reading this article.</p>

<p>The YAGNI (â€˜You arenâ€™t gonna need itâ€™) principle is well-known in the agile world, going back to XP (as in â€˜eXtreme Programmingâ€™, not â€˜Windows XPâ€™) in the end of 1990s. Unfortunately, this concept is too open to interpretation, which causes lots of confusion and heated debates both in industry [<a href="#[Fowler04]">Fowler04</a>] [<a href="#[Devijver08]">Devijver08</a>] [<a href="#[Litzenberger11]">Litzenberger11</a>] and in academia [<a href="#[Boehm02]">Boehm02</a>].</p>

<p>This article describes a practical approach to YAGNI, which has been tried in practical agile projects (one of which has had releases to millions of customers every 2â€“4 weeks). For the purposes of this article, weâ€™ll name it YAGNI-C (as â€˜YAGNI-Clarifiedâ€™). While not being universal, we hope that YAGNI-C might be useful in quite a wide range of projects. Oh, and if somebody is about to say â€œHey, weâ€™ve been doing exactly the same things for yearsâ€ â€“ of course, YAGNI-C is not something really new; the problem is that such practices (which we think are best practices) are not often described, and therefore cannot be widely used.</p>

<h2>The very beginning</h2>

<p>The story starts when weâ€™re about to start our new agile project to make our super-duper app. The first question is â€“ are we going to have some architecture? In general, it depends, but letâ€™s consider projects where architecture is essential, so the answer is â€˜yesâ€™. The second question is â€“ within the architecture chosen, are we going to have our own set of libraries (letâ€™s name them â€˜infrastructure librariesâ€™) which needs to be common for a significant part of project? Again, in general, it depends, but letâ€™s assume that in our project (for example, due to the project size/complexity) weâ€™ve decided to have such a set of infrastructure libraries (it may be just a glue, or something more substantial â€“ it doesnâ€™t matter too much, the key thing is that these libraries are supporting a big part of the whole project). Now, letâ€™s assume that APIs to these libraries are designed and supported by one or more people, letâ€™s name them â€˜library API maintainersâ€™ (with a hope that there is at least one of the architects involved in this group). Now letâ€™s try to define some principles and procedures of how â€˜library API maintainersâ€™ should approach YAGNI within our YAGNI-C model.</p>

<h3>Thinking, not implementing</h3>

<p>The First Principle in YAGNI-C is that â€˜thinking ahead is good, implementing ahead is badâ€™. While the second part of the First Principle is actually YAGNI in its pure form, the first part of the First Principle may need a bit more of explanation. There are numerous complaints out there (see, for example, [<a href="#[Fowler04]">Fowler04</a>]) that YAGNI is (or at least can be) misused to the point where any thinking about architecture is prohibited, and the project becomes a mess of ad hoc tactical decisions. The other side of the spectrum (library which does everything in sight) is also well-known to have led to disasters (ALGOL&nbsp;68, DCE RPC, and especially X.500 are good examples of the over-designed systems which were so complicated that nobody was able to implement them properly). The First Principle above aims to strike the balance between these two undesirable extremes, and in practice it seems to work reasonably well (while in some cases, preliminary proof-of-concept prototypes may be needed before First Principle can be applied, starting from post-prototype development seems to work pretty well).</p>

<p>One other way to look at the First Principle is to rephrase it as â€˜as long as you can think about design without starting to implement it â€“ youâ€™re fine, anything beyond that is over-designâ€™. Essentially it restricts the amount of â€˜thinking aheadâ€™ to the amount of information which fits into the heads of the â€˜library API maintainersâ€™, which is subject to the cognitive limitations of the human brain, so it is fairly limited. In fact, the First Principle is much closer to the â€˜very leanâ€™ end of spectrum, while still allowing a certain amount of thinking ahead.</p>

<h3>Specific cases</h3>

<p>The Second Principle of YAGNI-C is â€˜if nobody in the team can describe a very specific use case for a problem â€“ the problem doesnâ€™t existâ€™ (and whatever doesnâ€™t exist doesnâ€™t need to be solved). This Second Principle is of extreme importance for the whole process to function. What it allows is the transfer of discussion from the space of â€œHey, why are we not using XYZ?â€ and â€œWhy we donâ€™t support paradigm ABC?â€ (which are subjects which can easily take months to deliberate on) to the space of very specific use cases, applicable to the current project, and while decisions might be not so obvious, at least it can be reasoned about not from the Swiftian big- and little-endians<sup><a href="#fn1">1</a></sup> point of view, but from the point of view where at least some logic can be applied.</p>

<h2>Prohibit misuses</h2>

<p>The Third Principle of YAGNI-C is â€˜If in doubt how it should behave â€“ prohibit itâ€™. If, as a library implementer, you donâ€™t have specification on a certain behaviour (for example, answering â€œwhat will happen if <code>
x.g() </code>will be called before <code>x.f()</code>â€ is not specified, and you yourself have doubts about what will happen in this case) â€“ you should prohibit such behaviour (for example, inserting an assertion, but other means are also possible).</p>

<p>This Third Principle is essentially a manifestation of agile principle known as â€˜deferring commitmentâ€™. In practice, whenever a library is released, people start using it in all kinds of ways, including those ways which were never intended. Prohibiting unintended uses (effectively deferring commitment of library writers regarding these uses) is good for at least two reasons: first, it makes code more reliable (making sure that caller really understands what is going on), and second, it allows implementation details to be hidden as deep as possible, reducing chances that library modifications which donâ€™t change the specification can break the client code.</p>

<h2>How it works</h2>

<p>Within YAGNI-C, the process of infrastructure API design is as follows.</p>



<ol>
<li>First, library API maintainers design a very minimalistic API.</li>

<li>Then, people from the rest of the project start to come and say, â€œHey, your library doesnâ€™t support this call, please add it.â€ According to the second principle, each such request MUST be accompanied with a specific use case â€“ â€œWHY this call is necessary?â€</li>

<li>This is a point where library API maintainers perform analysis, deciding if a new call (class/...) should be added to the library API. As practice shows for good library design, about 30% of requests from step 2 above are turned down as â€œYouâ€™re solving the wrong problem, what you really need for your use case is...â€, another 50% are turned down as â€œThis can be done using existing API as follows:...â€, and remaining 20% lead to extending the APIs. And as â€˜library API maintainersâ€™ did think about potential requests (see the First Principle), implementing additional calls is normally not that a big deal.</li>

<li>Rinse and repeat from step 2.</li>

</ol>

<p>It should be noted that YAGNI-C is substantially iterative, and therefore canâ€™t possibly work in strictly-waterfall development environments.</p>

<h3>Example</h3>

<p>Letâ€™s take a look and see on a specific example, how YAGNI-C might work in practice. Of course, this example is inherently extremely limited and oversimplified, but it still provides a good illustration of the concepts involved.</p>

<p>Letâ€™s assume that Alice is a library API maintainer, and one of the classes she develops, is a class <code>
File</code> (Listing 1).</p>

<table class="sidebartable">
	<tr>
		<td>
			<pre class="programlisting">
class File {
  FILE* f;
  public:
  File( const char* filename ) {
    f = fopen( filename, ... ); }
  size_t read( char* buf, size_t bufsize ) {
    /* ... */ }
  void write( const char* buf, size_t bufsize ) {
    /* ... */ }
  ~File() { fclose( f ); }};
			</pre>
		</td>
	</tr>
	<tr>
		<td class="title">Listing 1</td>
	</tr>
</table>

<p>This class, as written, has a problem: it has an implicit copy constructor, which, combined with the nature of <code>~File()</code>, will cause all kinds of problems. Now, Alice faces a question: what to do about it? One thought quickly crosses her mind: to add something like Listing 2 but she quickly realizes that as there is no requirement to copy class <code>File</code>, this is a feature which would violate our First Principle. Now, to comply with both the First Principle and the Third Principle, she writes Listing 3.</p>

<table class="sidebartable">
	<tr>
		<td>
			<pre class="programlisting">
File( const File&amp; ff )
{
  f = fdopen( dup( fileno( ff.f ) ) );
}
File&amp; operator =( const File&amp; ff )
{
  fclose(f);
  f = fdopen( dup( fileno( ff.f ) ) );
}
			</pre>
		</td>
	</tr>
	<tr>
		<td class="title">Listing 2</td>
	</tr>
</table>

<table class="sidebartable">
	<tr>
		<td>
			<pre class="programlisting">
private: //copying/assigning of File
         //objects is prohibited
File( const File&amp; );
File&amp; operator=( const File&amp; );
//in C++11, File( const File&amp; ) = delete;
// and File&amp; operator =( const File&amp; ) = delete;
// can be used instead
			</pre>
		</td>
	</tr>
	<tr>
		<td class="title">Listing 3</td>
	</tr>
</table>

<p>This construct prevents other classes from calling the <code>File</code> copy constructor/assignment operator. This implementation is consistent with all the principles stated above.</p>

<p>Some time later, Bob comes to Alice and complains, â€œHey, why donâ€™t you support a copy constructor for <code>
File</code>?â€. Given such a request, it is impossible to judge if it has merits or not, as it is not clear exactly what problem Bob faces; formally, this request violates the Second Principle and is therefore denied. As a next step, Bob elaborates:</p>

<p class="blockquote">The following piece of code doesnâ€™t compile:<code>  void f( File ff ) { /* ... */ }</code>
</p>

<p>Now request is specific enough, but it immediately becomes obvious (at least to Alice) that Bob has just forgot to put <code>&amp;</code> in the function declaration, so his problem can be solved without introducing a copy constructor for the class <code>File</code>.</p>

<p>At some point, Charlie comes to Alice and complains:</p>

<p class="blockquote">Why is the assignment operator prohibited for class <code>File</code>? I want to copy a file and am trying to write:
<pre class="programlisting">
    File f1( filename1 );
    File f2( filename2 );
    f1 = f2;//compiler errorâ€
</pre>
</p>	
<p>Once again, when a specific use case is provided, it is obvious that adding an assignment operator to <code>
File</code> would be quite the wrong thing to do to solve Charlieâ€™s problem, so Alice explains to Charlie how he can implement file copying for <code>File</code> (or she may decide to add static <code>File::copy()</code> for this purpose).</p>

<h2>Summary</h2>

<p>YAGNI-C is an attempt to clarify YAGNI so it becomes less vague and easier to follow. While YAGNI-C (though not under this name) has been successfully used for agile projects, it is certainly not a silver bullet, so youâ€™ll still think to think if it is beneficial for your project. It should not be considered as a new approach to development (we know many teams which follow these or very similar approaches), but as a new way to describe existing best practices.</p>

<img src="http://accu.org/content/images/journals/ol117/Ignatchenko/Ignatchenko-1.png" />


<h2>References</h2>

<p class="bibliomixed"><a id="[Boehm02]"></a>[Boehm02]  Boehm, B. , â€˜Get ready for agile methods, with careâ€™ <em>
Computer</em>, vol 35</p>

<p class="bibliomixed"><a id="[Devijver08]"></a>[Devijver08]  Steven Devijver, 1The YAGNI Argument (You Ainâ€™t Gonna Need It)â€™ <a href="http://architects.dzone.com/news/yagni-argument-you-aint-gonna-">http://architects.dzone.com/news/yagni-argument-you-aint-gonna-</a></p>

<p class="bibliomixed"><a id="[Fowler04]"></a>[Fowler04]  â€˜Is Design Dead?â€™ Martin Fowler, <a href="http://martinfowler.com/articles/designDead.html">http://martinfowler.com/articles/designDead.html</a></p>

<p class="bibliomixed"><a id="[Litzenberger11]"></a>[Litzenberger11] Dwayne C. Litzenberger, â€˜The Price of YAGNIâ€™ <a href="https://www.dlitz.net/blog/2011/02/the-price-of-yagni/">https://www.dlitz.net/blog/2011/02/the-price-of-yagni/</a></p>

<p class="bibliomixed"><a id="[Loganberry04]"></a>[Loganberry04] David â€˜Loganberryâ€˜, â€˜Frithaes! â€“ an Introduction to Colloquial Lapine!â€™ <a href="http://bitsnbobstones.watershipdown.org/lapine/overview.html">http://bitsnbobstones.watershipdown.org/lapine/overview.html</a></p>

<h2>Acknowledgement</h2>

<p>Cartoon by Sergey Gordeev from Gordeev Animation Graphics, Prague.</p>

<p class="footnotes"></p>
<ol>
<li><a name="fn1"></a>Not to be confused with Intel/DEC little- and big-endians</li>
</ol>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
