<rss version="2.0"><channel><title>RSS feed for InstantSpot site orangepips</title><link>http://orangepips.instantspot.com</link><language>en-us</language><copyright>This work is Copyright &#xA9; 2008 by orangepips</copyright><generator>RSSVille ColdFusion FeedMaker, version 1.0</generator><pubDate>Thu, 24 Jul 2008 10:39:38 GMT</pubDate><item><title>TDD Backlash</title><link>http://orangepips.instantspot.com/blog/2008/03/03/TDD-Backlash</link><description>&lt;p&gt;It&apos;s been said, &amp;quot;&lt;a href=&quot;http://www.bartleby.com/59/3/foolishconsi.html&quot;&gt;A foolish consistency is the hobgoblin of little minds&lt;/a&gt;.&amp;quot; And, in my experience TDD can easily slide into this fallacy. So it gladens me to see someone like C&amp;eacute;dric Beust, creator of the &lt;a href=&quot;http://testng.org/doc/&quot;&gt;TestNG unit testing framework&lt;/a&gt;, &lt;a href=&quot;http://beust.com/weblog/archives/000477.html&quot;&gt;call out the TDD zealots&lt;/a&gt;. In addition he also offers some heuristics that I think really capture the essence of how unit testing should be approached.&lt;/p&gt;
&lt;p&gt;To wit, I tried introducting unit testing at my workplace and ran into this very problem. But, some background first:&lt;/p&gt;
&lt;p&gt;The product I work on is closing in on a decade of development. And stuff that was almost 10 years ago, which is still around and used, has UI, database I/O and business logic all intertwined. Very much a &lt;a href=&quot;http://en.wikipedia.org/wiki/Model_1&quot;&gt;Model 1&lt;/a&gt; architecture. But, before you start ranting about bad design practices and MVC and so forth, know the product works, and makes money. And, it started out in Coldfusion 4. So objects were not an option and Fusebox was nascent at best.&lt;/p&gt;
&lt;p&gt;With a codebase like this, you cannot just flip a switch and make it unit testable. Anyone who proclaims changes to said code must be unit testable is not living in reality. It&apos;s possible to &lt;a href=&quot;http://www.amazon.com/Working-Effectively-Legacy-Robert-Martin/dp/0131177052&quot;&gt;move in that direction&lt;/a&gt;, but if it took you years to create that codebase, don&apos;t expect it to take days, weeks or months to get to a unit testable state. These things are intertwined and must be broken apart carefully with planning and coordination with testing.&lt;/p&gt;
&lt;p&gt;Programming is fundamentally just as much a social and technical problem. Attempting to impose a command and control structure on programmers == bad idea. But the appeal of implementing a &lt;em&gt;Good Idea&lt;/em&gt; as the &lt;em&gt;Only Idea&lt;/em&gt; can be overwhelming.&amp;nbsp; This was definitely the case for my environment, where instead of focusing on the notion of having good unit tests, TDD ruled the day and it became &lt;em&gt;you must have unit tests before you code&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;This crashed and burned rather quickly as developers pushed back.&lt;/p&gt;
&lt;p&gt;Now personally I write unit tests for my code that does not involve database I/O or UI. Where I find the configuring the dependencies, even through injection, outweigh the benefits of unit testing. But as a result, most code that I write separates these aspects out leaving everything else in a unit testable state.&lt;/p&gt;
&lt;p&gt;What I do find is that sometimes unit tests makes maintenance easier. But, that sometimes if the change is large, I need to throw out the old tests. Maybe I write new tests or maybe I don&apos;t. It just depends on complexity and time. And, for TDD adherents I am sure this is probaby heresay.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description><pubDate>Mon, 03 Mar 2008 19:17:00 GMT</pubDate><guid>http://orangepips.instantspot.com/blog/2008/03/03/TDD-Backlash</guid><category>Coldfusion,Unit Testing</category></item><item><title>XML StAX Processing with Coldfusion</title><link>http://orangepips.instantspot.com/blog/2007/03/28/XML-StAX-Processing-with-Coldfusion</link><description>&lt;p&gt;Several problems with Coldfusion XML processing and solution set:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;&lt;strong&gt;Slow&lt;/strong&gt;: due to DOM processor (&lt;a href=&quot;http://xerces.apache.org/&quot;&gt;Xerces&lt;/a&gt;)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Inconsistent Round-Tripping&lt;/strong&gt; (i.e. 	serialization / deserialization) :
    &lt;ol&gt;
        &lt;li&gt;(un-) escaping characters&lt;/li&gt;
        &lt;li&gt;non-printable characters&lt;/li&gt;
        &lt;li&gt;missing / multiple XML declaration(s)&lt;/li&gt;
        &lt;li&gt;character set problems&lt;/li&gt;
        &lt;li&gt;et al.&lt;/li&gt;
    &lt;/ol&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Kludgy Tree API&lt;/strong&gt; yes you can use structure and 	array functions, just don&apos;t like it.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Note, don&apos;t see this as a flame on Adobe/Macromedia. The Coldfusion XML implementation uses best available technology at the time and APIs that fit in with the language paradigm. Just have better options now.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Slow Solution&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;http://woodstox.codehaus.org/&quot;&gt;Woodstox&lt;/a&gt;&lt;/strong&gt;: &lt;a title=&quot;CFDJ: Advanced XML Processing with StAX in ColdFusion&quot; href=&quot;http://coldfusion.sys-con.com/read/236002.htm&quot;&gt;Jim Collins wrote a CFDJ article about using a StAX XML processor with Coldfusion&lt;/a&gt;. Unfortunately, as near as I can tell, his &lt;a href=&quot;http://sourceforge.net/projects/cfsynergy&quot;&gt;open source project to integrate Coldfusion with Woodstox&lt;/a&gt; was never released. &lt;a title=&quot;SUN: Streaming APIs for XML Parsers&quot; href=&quot;http://java.sun.com/performance/reference/whitepapers/StAX-1_0.pdf&quot;&gt;Testing demonstrates&lt;/a&gt; a StAX processor, such as Woodstox, provides very efficient (read: fast) XML processing, and a more intuitive API, than a SAX processor. But still not intuitive enough for me. So enter...&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Round-Tripping &amp;amp; API Solutions&lt;br /&gt;
&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a title=&quot;XML object model&quot; href=&quot;http://www.xom.nu/&quot;&gt;XOM&lt;/a&gt;&lt;/strong&gt; provides a very easy to use API that roundtrips XML like a champ. Correct I/O is XOM&apos;s middle name. But it doesn&apos;t integrate natively with a StAX processor unless you use...&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;http://dsd.lbl.gov/nux/&quot;&gt;NUX&lt;/a&gt; &lt;/strong&gt;is like a Swiss Army knife for XML. But the purpose of this entry just know it&apos;s the glue between XOM and Woodstox (&lt;em&gt;note that NUX includes the XOM jar so you do not need to download it separately&lt;/em&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Code&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Download the Woodstox and NUX jars and configure them in your Coldfusion classpath. The examples below build upon each other.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Setup&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;Creates a &lt;a href=&quot;http://www.xom.nu/apidocs/nu/xom/Builder.html&quot;&gt;XOM Builder object&lt;/a&gt; backed by a StAX processor.&lt;font face=&quot;courier new,courier&quot;&gt; &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size=&quot;2&quot; face=&quot;courier new,courier&quot;&gt;inputFactory = createObject(&amp;quot;java&amp;quot;, &amp;quot;com.ctc.wstx.stax.WstxInputFactory&amp;quot;).init()&lt;br /&gt;
builder = createObject(&amp;quot;java&amp;quot;, &amp;quot;nux.xom.io.StaxUtil&amp;quot;).createBuilder(local.joInputFactory, javacast(&amp;quot;null&amp;quot;, &amp;quot;&amp;quot;)&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;u&gt;XMLParse() Alternative&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;Returns a &lt;a href=&quot;http://www.xom.nu/apidocs/nu/xom/Document.html&quot;&gt;XOM Document object&lt;/a&gt;. Note: provide &lt;em&gt;XMLString &lt;/em&gt;variable.&lt;/p&gt;
&lt;p&gt;&lt;font size=&quot;2&quot; face=&quot;courier new,courier&quot;&gt;document = builder.create(XMLString)&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;u&gt;XMLSearch() Alternative&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;Returns a &lt;a href=&quot;http://www.xom.nu/apidocs/nu/xom/Nodes.html&quot;&gt;XOM Nodes object&lt;/a&gt; (i.e. an iterator of Node objects). Note: provide &lt;em&gt;XQueryString&lt;/em&gt; variable.&lt;/p&gt;
&lt;p&gt;&lt;font size=&quot;2&quot; face=&quot;courier new,courier&quot;&gt;nodes = createObject(&amp;quot;java&amp;quot;, &amp;quot;nux.com.xquery.XQueryUtil&amp;quot;).xquery(document, XQueryString)&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size=&quot;2&quot; face=&quot;courier new,courier&quot;&gt;loop from=&amp;quot;0&amp;quot; to=&amp;quot;#nodes.size() - 1#&amp;quot; index=&amp;quot;idx&amp;quot; &lt;br /&gt;
element = nodes.get(javacast(&amp;quot;int&amp;quot;, idx)) &lt;br /&gt;
attributeValue = element.getAttribute(&amp;quot;attributeName&amp;quot;).getValue() &lt;br /&gt;
attributeText = element.getValue &lt;br /&gt;
/loop &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;u&gt;ToString() Alternative&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;Creates a string representation of the XML.&lt;/p&gt;
&lt;p&gt;&lt;font size=&quot;2&quot; face=&quot;courier new,courier&quot;&gt;XMLString = document.toXML()&lt;/font&gt;&lt;/p&gt;</description><pubDate>Wed, 28 Mar 2007 15:04:00 GMT</pubDate><guid>http://orangepips.instantspot.com/blog/2007/03/28/XML-StAX-Processing-with-Coldfusion</guid><category>XML,Coldfusion</category></item></channel></rss>