<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ThotSpots &#187; code generators</title>
	<atom:link href="http://www.thotspots.com/tag/code-generators/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thotspots.com</link>
	<description>Agile Software Development</description>
	<lastBuildDate>Wed, 09 Sep 2009 18:13:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Removing Code Generators from the Build Process</title>
		<link>http://www.thotspots.com/removing-code-generators-from-the-build-process/</link>
		<comments>http://www.thotspots.com/removing-code-generators-from-the-build-process/#comments</comments>
		<pubDate>Fri, 03 Aug 2007 17:04:16 +0000</pubDate>
		<dc:creator>Craig Jones</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[code generators]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[software engineering]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.maximsc.com/removing-code-generators-from-the-build-process/</guid>
		<description><![CDATA[I&#8217;m a huge fan of code generators.  I&#8217;ve seen them used successfully in many different ways.  In the Java world, for example, the Xdoclet parser is commonly used to generate object code and ORM mappings based on database schema &#8212; a huge timesaver.  I&#8217;ve also seen creative uses of XSTL transforms and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a huge fan of code generators.  I&#8217;ve seen them used successfully in many different ways.  In the Java world, for example, the Xdoclet parser is commonly used to generate object code and ORM mappings based on database schema &#8212; a huge timesaver.  I&#8217;ve also seen creative uses of XSTL transforms and Velocity templates for handily generating all kinds of program code.  There are generally two ways to take advantage of code generators.  One is for software developers to invoke the code generators on demand, as they program.   The other is to incorporate code generators as part of a &#8220;daily build&#8221; (i.e. some automated build process using Ant, Maven, another build tool, or handcrafted scripts/batch files).  Lately, I&#8217;ve gotten soured on the latter.<span id="more-35"></span></p>
<p>Case in point: On a project where we were upgrading a system from Java 1.4 to Java 5, I happened to be the first developer to check in code with Java 5 type safety notation (which uses angle brackets) in a file that happened to be processed by a Hibernate 2 Xdoclet parser during the build process (if necessary).  I didn&#8217;t realize that the Xdoclet parser didn&#8217;t know how to handle those angle brackets.  Furthermore, I didn&#8217;t notice the problem because of the way the Ant script was set up, it didn&#8217;t manifest until after running a CLEAN task, but I had no reason to run CLEAN (just BUILD). So, instead, an unsuspecting developer on the East Coast was made to suffer, puzzling over the problem until I came online three hours later and realized what had happened.</p>
<p>So, in my experience, code generators seem to be much more successful when used as tools that are invoked on demand by the developers.  The key distinction is whether or not the generated code is committed to version control.  Looking back over the last seven projects that I&#8217;ve been involved with that made heavy use of code generators, three of them did so with post-commit generation.  The four projects that used on-demand generation always seems to work out much better.  On-demand generation simplifies much:</p>
<ol>
<li>The build process is faster and more direct, with less to go wrong at build time, which is beyond the control of the committing developer.  This is especially important when automating the build process to be unattended, with tools like Cruise Control.</li>
<li>Newbie developers do not need to be aware of the existence of the code-generation tools at all (until their first assignment that requires one).  That&#8217;s less to go wrong when setting up a new development environment.</li>
<li>Exceptions to the rule can be handled manually.  No need to spend hours perfecting rickety RegEx replacement tasks in Ant.  (By all means, utilize RegEx replacement tasks when it is cost effective to spend the time writing them, but this way you get to choose when that is, rather than being forced into it.  Also, this way it won&#8217;t kill you if the transform is not perfect.)</li>
<li>There is high visibility of the generated code.  What&#8217;s checked in to version control is what you get.  The exact changes are logged and can be easily differenced/compared/branched/tagged, just like any other code.  There&#8217;s no question as to what the compiler is &#8220;really&#8221; going to compile and deploy.</li>
<li>By putting the developer in the loop between the code generation and the commit, it gives Eclipse a chance to chime in about errors and warnings.<br />
Also, if Eclipse can see the generated code, that means that all the power and might of the searching, navigating, and refactoring tools come into play.</li>
<li>When the code generators make bad decisions (e.g. when presented with a new kind of input), the results are more easily noticed because the developer facing the problem is the one who just did the on-demand code generation.  Chances are, the problem will manifest as a blatant error, warning, or hint, or as unit test failure.  Even if not, the committing developer might catch it still if he/she is disciplined in comparing the differences of every single file that he/she is about to check in (a good practice anyway for catching things like typos, unaddressed TODO&#8217;s, and extraneous debugging logic).</li>
<li>It&#8217;s easer for developers to mix and match tools, applying them in any arbitrary order, as opposed to the ones that are programmed in to the build process always having to be last.</li>
</ol>
<p>I admit there are some downsides:</p>
<ol>
<li>Having to make sure the developers know when and how they are supposed to use the tools, at the risk of them thinking they need to do the work by hand.</li>
<li>Remembering to revisit previously generated code whenever a code generator process changes, and either manually affecting the changes, or regenerating that code and merging back in any modifications that were done by hand.  (Fortunately tools like WinMerge and Beyond Compare make this easier.)</li>
</ol>
<p>There are undoubtedly more cons (as well as pros), but I&#8217;m convinced that the cons are easily managed and that the &#8220;low road&#8221; is the easier route.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thotspots.com/removing-code-generators-from-the-build-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

