{ |one, step, back| } http://www.onestepback.org/index.cgi Jim Weirich's Blog en-us { |one, step, back| } http://onestepback.org http://onestepback.org/images/jwface.gif How did you get started in software development. http://www.onestepback.org/index.cgi/Tech/Programming/SoftwareDevelSteps.red <h2>Tagged</h2> <p>Looks like <a href="http://objo.com/2008/6/7/how-did-you-get-started-in-programming">Joe O&#8217;Brien</a> tagged me for answers to the following questions. He, in turn, was tagged by <a href="http://joshholmes.com/">Josh Holmes</a>, who in turn was tagged by <a href="http://www.jeffblankenburg.com/index.html">Jeff Blankenburg</a>. It looks like <a href="http://www.codinggeekette.com">Sarah Dutkiewicz</a> and <a href="http://michaeleatonconsulting.com/blog/archive/2008/06/04/how-did-you-get-started-in-software-development.aspx">Micheal Eaton</a> started this.</p> <p>OK, sounds like fun. Here goes.</p> <h2>How old were you when you started programming?</h2> <p>I was introduced to programming in high school by reading a book on the topic. The book taught me how to write machine code for a strange decimal-based machine. Unfortunately, there was no actual computer involved in the process. Shoot, who had computers back then? Certainly not our high school (the personal computers? not invented yet!)</p> <p>In college, I learned a smattering of <span class="caps">FORTRAN</span>. Just enough to drive a Calcomp plotter to plot data from my undergraduate physics courses. But didn&#8217;t really get into programming until my junior year in college. (Story continued in next question)</p> <h2>How did you get started in programming?</h2> <p>So, I was planning out the courses for my junior year in college and I had a hole in my math courses. The math class I needed was not offered that semester, so my adviser suggested taking a computer programming course. He said it would be useful and, who knows, I might enjoy it.</p> <p>So I signed up for an introduction to <span class="caps">FORTRAN</span> course, figuring it would be easy because I already knew a little bit of <span class="caps">FORTRAN</span>. I show up on the first day of class and after a few preliminaries the instructor jumps right into some code, that looked like this:</p> <pre> (de member (pip deck) (cond ((null deck) nil) ((eq pip (car deck)) t) (t (member pip (cdr deck))))) </pre> <p>I remember scratching my head and thinking this was the strangest <span class="caps">FORTRAN I</span> had ever seen. I was totally confused for about three days, then something clicked on the third day of class. I suddenly &#8220;<em>got</em>&#8221; what the instructor was trying to get across and it all made perfect sense.</p> <p>If you haven&#8217;t figured it out yet, the instructor taught us Lisp as part of an introduction to <span class="caps">FORTRAN</span>. The instructor turned out to be Daniel Friedman, the author of <a href="http://www.amazon.com/Little-LISPer-Third-Daniel-Friedman/dp/0023397632"><em>The Little Lisper</em></a>, and was well known in the Lisp community. That small exposure to Lisp hooked me on programming from that point on. I took as many CompSci courses as I could in my remaining year and a half in college. I eventually graudated with a BS in Physics, but had a strong background in Computer Science as well.</p> <h2>What was your first language?</h2> <p>Technically, <span class="caps">FORTRAN</span> was my first language. But Lisp is the language I fell in love with and is what got me hooked on programming.</p> <h2>What was the first real program you wrote?</h2> <p>I have a very clear memory of the very first program I wrote professionally. The reason it is so clear is that this was the first program I wrote that was intended for actual use by someone who wanted it. Everything else up to that time was done for my own personal enjoyment or to satisfy some course requirement.</p> <p>The program calculated the &#8220;critical angles&#8221; of &#8220;pieces&#8221;. I was given the requirements by Anne Exline, a senior programmer, and proceeded to write the program to spec. It took a few days, but when I was done I showed the result to Anne and she was pleased with the result.</p> <p>The funny thing is that I had no idea what a &#8220;piece&#8221; was nor what was so critical about the angles I was calculating. I was so excited about writing an actual program that I did not ask until the software was done. When asked, Anne just looked at me funny and said &#8220;Rocket Pieces&#8221;. When Cape Canaveral lauches a rocket, they track it very carefully to make sure it stays on course. If it strays, the range safety officer is required to activate the self destruct. The critical angles are those angles that would cause the &#8220;rocket pieces&#8221; to land outside the safety area of the flight path.</p> <p>So, my very first professional program was not only useful, it might actually save lives.</p> <h2>What languages have you used since you started programming?</h2> <p>Languages I have used as part of my professional career (in roughly chronological order) include <span class="caps">FORTRAN</span>, various assembly languages, <span class="caps">FORTH</span>, C, PL/M, C++, Java, Ruby.</p> <p>Languages I have used in addition to those mentioned above: Pascal, Perl, Eiffel, and Lisp/Scheme.</p> <p>Languages I can read, but never wrote anything significant in them: Ada, Python, Erlang, Smalltalk, <span class="caps">SNOBOL</span>, Algol, Pascal.</p> <h2>What was your first professional programming gig?</h2> <p>I was hired by the <span class="caps">RCA</span> Missile Test project in Cape Canaveral, Florida as a Near Real Time Analyst. Duties included programming various launch related software (e.g. the critical angle program mentioned above) and working launch support.</p> <p>The launch support was the &#8220;Near Real Time&#8221; part of the job description. From the moment a rocket is launched until it reaches orbital velocity, any malfunction could cause it to fall back to earth. During this initial portion of the launch, the launch is monitored in &#8220;real-time&#8221; so that we know exactly where it would land if the engines were to cut off <span class="caps">NOW</span>. Trajectory calculations had to be done in fractions of a second and updated constantly in real time.</p> <p>After the rocket reaches oribital velocity (usually somewhere between 8 and 14 minutes into its flight), it won&#8217;t fall back to earth. At this point the real time trajectory program is shut down and the near real time program is started. The near real time program can take a few minutes to calculate a more exact orbital prediction and then send that prediction to downrange radars (e.g. the the <a href="http://en.wikipedia.org/wiki/Ascension_Island">Ascension Island</a> station) that won&#8217;t see the rocket until about 20 minutes after launch. It was the job of the Near Real Time analyst to run that program and provide oribital predictions for downrange station.</p> <h2>If there is one thing you learned along the way that you would tell new developers, what would it be?</h2> <p>Find something that you enjoy and do that. Life is too short to work in a job that you dislike.</p> <h2>What’s the most fun you’ve ever had … programming?</h2> <p>Oh, the fun I have had. This story still makes me smile.</p> <p>My first computer was a single board <span class="caps">Z80</span> microcomputer with 4 KB of memory. I wrote a small <span class="caps">FORTH</span>-like interpreter for it and hacked a version of the animal game in <span class="caps">FORTH</span>. The animal game is a program that plays 20 questions to figure out what animal you are thinking of. It constructs a binary tree where each node is a question and the subtrees are the yes and no answers to the question. To play the game, all the program does is walk the tree, ask the question at the current node and follow either the <span class="caps">YES</span> branch or the NO branch as appropriate.</p> <p>If the program guesses wrong, it will ask you for your animal and a question that will distinguish your animal from the one it guessed. It then adds your question to the tree. By this extremely simple mechanism, it is able to expand its knowledge base. (see <a href="http://www.rubyquiz.com/quiz15.html">Ruby Quiz #15</a> for more details).</p> <p>I had just finished the program and had seeded it with a single animal, a mouse. I turned to my wife and asked her to play the game. She thinks of an animal and starts the program, which immediately asked her &#8220;Is it a mouse?&#8221;. She turned to me with surprise and said &#8220;How did it know?&#8221;. Of course, the animal she picked was a mouse.</p> <p>I don&#8217;t think I have ever impressed anyone with my programming skills as much as she was impressed with that game.</p> <h2>Who&#8217;s up next?</h2> <p>I&#8217;m tagging the following people. Remember, this is entirely voluntary so don&#8217;t feel obligated to answer. But I&#8217;m betting the answers are interesting:</p> <ul> <li><a href="http://mysterycoder.blogspot.com/">Chris Nelson</a></li> <li><a href="http://clarkware.com/cgi/blosxom">Mike Clark</a></li> <li><a href="http://gilesbowkett.blogspot.com/">Giles Bowkett</a></li> <li><a href="http://railsstudio.com/">Mark Windholtz</a></li> <li><a href="http://www.vanderburg.org/Blog">Glenn Vanderburg</a></li> </ul> On my wall ... http://www.onestepback.org/index.cgi/Tech/Programming/DarthTest.red <p><img src="http://onestepback.org/images/rublog/DarthTest.jpg" alt="" /></p> <p>(from <a href="http://www.flickr.com/photos/sebastian_bergmann/2282734669/sizes/o/">here</a>)</p> Color Blind http://www.onestepback.org/index.cgi/Tech/Programming/ColorBlind.red <p style="padding-left:3em;"><em>Presented a talk on Test First Design today at work.</em></p> <p>I did a Lunch &#38; Learn presentation today at work on the topic of unit testing and Test First Design, included a discussion of the <span style="color:red;">Red</span> / <span style="color:green;">Green</span> / <span style="color:blue;">Refactor</span> technique. Unfortunately the red gun on the video projector was bad, ruining all the careful color coding I put in to my slides. So the technique will now be officially called <span style="color:black;">Black</span> / <span style="color:yellow;">Yellow</span> / <span style="color:blue;">Refactor</span>.</p> Tuning Performance http://www.onestepback.org/index.cgi/Tech/Programming/Performance.red <p><em>Uncle Bob has a couple examples of why performance tuning almost always has surprises in store for you.</em></p> <h2>Not What You Expect!</h2> <p>Bob Martin (Uncle Bob) <a href="http://www.butunclebob.com/ArticleS.UncleBob.PerformanceTuning">relates</a> a couple of stories on performance tuning and why your expectations are nearly always wrong.</p> <p>The moral of the story &#8230; measure, measure, measure whenever you have a performance problem. The root cause is prabably not where you expect it to be.</p> Dependency Injection Gone Bad http://www.onestepback.org/index.cgi/Tech/Programming/DependencyInjectionGoneBad.red <p style="padding-left:3em;"><em>It always bothers me to see mock objects creating and returning other mock objects.</em></p> <h2>David Chelimsky on Dependencies</h2> <p><a href="http://www.butunclebob.com/ArticleS.DavidChelimsky">David Chelimsky</a> of <a href="http://www.objectmentor.com">Object Mentor</a> <a href="http://www.butunclebob.com/ArticleS.DavidChelimsky.DependencyInjectionIsOnlyMostlyGood">notes</a> that dependency injection eases the pain of dependencies so much that we sometimes don&#8217;t bother to root out the <em>bad</em> dependencies. Read the <a href="http://www.butunclebob.com/ArticleS.DavidChelimsky.DependencyInjectionIsOnlyMostlyGood">article</a> and pay close attention to the dependencies in the original and final versions (I drew a couple <span class="caps">UML</span> diagrams to keep it clear in my head).</p> <p>Plus its got a great <a href="http://en.wikiquote.org/wiki/The_Princess_Bride#Miracle_Max">Princess Bride</a> reference!</p> Coding Standards -- Keep It Simple http://www.onestepback.org/index.cgi/Tech/Programming/ShortCodingStandards.red <p>The last several clients I have worked for loved to publish huge coding standards documents. A recent one was only 20 pages long (and that was one of the shorter ones).</p> <p>While browsing the new <a href="http://rubyonrails.com">Rails 1.0 web site<sup><a href="#fn1">1</a></sup></a>, I stumbled upon the Rails coding standard. Here it is in full (<a href="http://dev.rubyonrails.org/">link</a>):</p> <ul> <li>Two spaces, no tabs</li> <li>MyClass.my_method(my_arg)&#8212;not my_method( my_arg ) or my_method my_arg</li> <li>Follow the conventions you see used in the source already</li> </ul> <hr /> <p id="fn1"><sup>1</sup> You <em>did</em> know that Rails 1.0 was <a href="http://weblog.rubyonrails.org/articles/2005/12/13/rails-1-0-party-like-its-one-oh-oh">released</a> today, right?</p> Thinking of no one in particular ... http://www.onestepback.org/index.cgi/Tech/Programming/AgileEvangelist.red <h2>Via <a href="http://www.livejournal.com/users/sirenian/27195.html">Elizabeth Keogh</a> ...</h2> <p><em>If an Agile Evangelist falls in the forest and there&#8217;s no one to hear him, does he still go on, and on, and on about it?</em></p> <p>(<a href="http://www.livejournal.com/users/sirenian/27195.html">link</a>)</p> Test VS Behavior http://www.onestepback.org/index.cgi/Tech/Programming/TestVSBehavior.red <p><em>This article was sparked by a some conversations and discussions at RubyConf 2005.</em></p> <h2>Test VS Behavior</h2> <p>It seems fashionable these days to say that <b>Test Driven Development</b> is not about <em>testing</em> at all, but rather about (<em>fill in the blank</em>), where the blank can be filled with &#8220;design&#8221;, &#8220;behavior&#8221; or &#8220;specification&#8221;. At RubyConf this year, one of the &#8220;informal&#8221; discussion sessions around the pool area drew a large crowd of people to discuss this very topic.</p> <p>The RSpec ruby library (from Steven Baker, Dave Astels and Aslak Hellesoy) is a replacement for Test::Unit. Its main focus is to change the terminology surrounding the whole <span class="caps">TDD</span> approach to software development. I think this is key &#8230; it is not changing anything fundamental about the processes, it is focused upon the words we use in describing the process. But don&#8217;t be fooled into thinking this is a matter of semantics only, for the very words we use to describe something shapes our thought processes about the thing we are describing.</p> <p><span class="caps">BDD</span>, or Behavior Driven Development, is an attempt to improve <span class="caps">TDD</span> (Test Drive Development) by emphasizing the behavior specification nature of traditional <span class="caps">TDD</span>. By freeing <span class="caps">TDD</span> from its test bound terminology, we avoid some of the preconceptions (e.g. &#8220;Tests? Yuck!&#8221;) that developers bring to the table when discussing <span class="caps">TDD</span>.</p> <h3>So What&#8217;s Different</h3> <p>So, what&#8217;s the real different between RSpec and Test::Unit? Compare these two code snippets. First the &#8220;test&#8221; version:</p> <pre> class TestEmptyMovieList &lt; Test::Unit::TestCase def setup @list = MovieList.new end def test_size_is_zero assert_equal 0, @list.size end end </pre> <p>And now the specification version:</p> <pre> class EmptyMovieList &lt; Spec::Context def setup @list = MovieList.new end def should_have_size_of_0 @list.size.should_equal 0 end end </pre> <p style="padding-left:3em;"><strong>Note:</strong> <em>This is from RSpec version 0.2.0 available as a gem from RubyForge. The RSpec guys are currently thinking about using domain specific language for specification. So expect RSpec to change in the future.</em></p> <p>We can see that the structure between the tests and the specifications is very similar. Actually, more than similar, they are virtually identical. We just use <code>Context</code> instead of <code>TestCase</code>, use methods with any name rather than those that start with <code>test_</code>, and use object based assertions rather than specific assert methods.</p> <p>The result is something that reads rather naturally in ruby-accented English. But the functionally is essentially that of Test::Unit, just in different clothing.</p> <h3>Just Semantics!</h3> <p>I hear you saying &#8220;But it&#8217;s just semantics!&#8221; Of course it is. But leave out the word &#8220;just&#8221;. When conveying meaning, semantics is everything. And one of the important features of Agile developement is to convey the meaning of the code, in the code itself.</p> <p>Semantics are important!</p> <h3>Is it worth it?</h3> <p>Ok, semantics are important. But is it worth converting all our unit tests into specifications?</p> <p>Maybe.</p> <p>I do find the terminology attractive. But I have a large investment in Test::Unit style tests at the moment. And RSpec is still a bit rough around the edges (for example, the error reporting is not quite as mature as Test::Unit&#8217;s). And RSpec is going through some major changes at the moment (I mentioned the specification <span class="caps">DSL</span> they are playing with).</p> <p>What would I like to see? One area of specification that current <span class="caps">TDD</span> practices tend to be weak in is the specification of preconditions. Preconditions define under what circumstances it is valid to call a method. For example, it may be invalid to call a square root function with a negative argument. Looking at a list of tests (umm &#8230; specs), I can&#8217;t be sure if negative inputs are not allowed, or if the spec writer just forgot the cover that case.</p> <p>I&#8217;m not ready to switch over to RSpec yet, but it certainly is moving in interesting directions.</p> <h3>What I didn&#8217;t talk about</h3> <p>Those of you who were present at the poolside conversation at RubyConf may wonder why I didn&#8217;t mention mock objects, since mock objects were a major part of that debate. I see the Behavior VS Test debate to be completely orthogonal to the Mock VS not-Mock discussion. I&#8217;ll pick up the mock object debate in another posting, so don&#8217;t worry.</p> When Clocks Go Bad http://www.onestepback.org/index.cgi/Tech/Programming/WhenClocksGoBad.rdoc Message <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/103140">ruby-talk:103140</a> on the ruby talk mailing list mentioned problems with the sleep command interacting in strange ways with setting the clock. That reminded me of this story. <p> Way back when, I used to work on a data acquisition system that used an IRIG clock reader to timestamp our data samples. An IRIG clock works by reading a signal that sends the time once every second. Between the second ticks, the clock reader would interpolate the time down to the millisecnod level. This allows you to have several clocks on different systems all synchronized to the same clock signal. </p> <p> Our system had to take a sample every 20 milliseconds, so every cycle we would calculate the time of the next cycle. When the current data cycle was done, we would just wait until that next scheduled time arrived to start the next cycle. </p> <p> An IRIG clock reader is an interesting device. Normally it works really well, but occasionally (especially if there is noise on the clock signal line) it will misread the time signal. One particular reader we were using tended to misread a couple of bits in the minutes data with the result that for one second, the clock reader would add 30 minutes to the real time. When the next clock signal arrived a second later, the reader would start reporting the correct time again. </p> <p> Jumping ahead was no problem. Our software just used the reported time and continued to schedule data cycles. However, when the clock jumped backwards, the next data cycle was suddenly scheduled for 30 minutes in the future. The result was that our system mysteriously stopped dead for 30 minutes and then just as mysteriously restarted as if nothing happened. </p> <p> Time is a strange concept in computer programs. It is difficult to know what the exact time is while executing. Consider the following lines of code &#8230; </p> <pre> t = Time.now # Line 1 puts &quot;The Current Time is: #{t}&quot; # Line 2 </pre> <p> One would think that line 2 will print the current time. And most of the time we would be correct. But suppose I pressed the suspend button on my laptop between line 1 and line 2. It might be hours (or days) before line 2 prints out its now &quot;out-of-date&quot; time message. </p> <p> When you are dealing with times in the millisecond range, there are all kinds of things that will pause your program from one line to the next. Interrupts, page faults, and time slicing all interact in interesting ways to make the concept of &quot;time&quot; in a program something of a challenge. </p> <p> It wasn&#8217;t hard to fix our cycle scheduler to be well behaved, even in the face of uncertain time. And I learned a new respect for time in the process. </p> Miller on Mock Objects http://www.onestepback.org/index.cgi/Tech/Programming/MillerOnMockObjects.rdoc Charles Miller reminds us that there are <a href="http://fishbowl.pastiche.org/2004/05/07/the_two_uses_of_mock_objects">two reasons</a> for using mock objects. <ol> <li>To create an environment where the object under test can live. </li> <li>To test that the object under test correctly modifies the environment. </li> </ol> <p> Each use requires a slightly different API (#1 sytle APIs tend to be more flexible than style #2). I&#8217;ve used both styles of APIs in the past (and had been frustrated trying to use a style #2 API in a style #1 situation), but I hadn&#8217;t connected the differences with the reason for the differences before. </p>