<?xml version="1.0" encoding="UTF-8" ?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc=" http://purl.org/dc/elements/1.1/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>briancarper.net (λ) (Tag: TDD)</title><link>http://briancarper.net/tag/158/tdd</link><description>Some guy's blog about programming and Linux and cows.</description><item><title>Books are our friends</title><link>http://briancarper.net/blog/books-are-our-friends</link><guid>http://briancarper.net/blog/books-are-our-friends</guid><pubDate>Sun, 30 Nov 2008 22:22:01 -0800</pubDate><description>&lt;p&gt;I went on a reading binge over Thanksgiving break.  Read on for reviews.&lt;/p&gt;

&lt;h2&gt;Test-Driven Development By Example&lt;/h2&gt;

&lt;p&gt;First I read &lt;a href=&quot;http://en.wikipedia.org/wiki/Test-Driven_Development_by_Example&quot;&gt;Test-Driven Development By Example&lt;/a&gt;.  This is a very short book, especially given the hefty price tag.  I would probably not have bought this if I'd seen it on a shelf at the store rather than online.&lt;/p&gt;

&lt;p&gt;That said, it's a good book if you want to understand the mindset behind the whole test-driven development fad.  The book is heavy on mindset and light on mechanics; it doesn't tell you how to set up an environment, how to compile and run tests, or any such thing.  It just goes through some examples and explains what the programmer was thinking, and how to tackle the problem from a TDD point of view.  The intended audience therefore is someone who has plenty of experience programming and wants to learn a new way to look at problem solving.&lt;/p&gt;

&lt;p&gt;The book goes through writing some terrible code (admittedly terrible by the author) to solve a simple problem, then refactoring the code to be less and less terrible by means of tests.  The writing style is engaging and casual and he describes mistakes as well as successes, which is a nice way to write a tutorial book.  The alternate writing style, belting out the correct answer the first time every time, is not as enlightening, and I appreciate it in this book.&lt;/p&gt;

&lt;p&gt;The book places a heavy emphasis on writing tests FIRST, making small incremental changes, and refactoring as you go.  It also explains how TDD can be related to various OOP design patterns, which I didn't find all that helpful.  And it describes some &quot;test patterns&quot;, which I found even less helpful.  But it's mostly an aesthetic objection; something about &quot;design patterns&quot; sits less and less well with me the more I get away from Java-like languages.  The information is still good, straightforward and to the point, take it or leave it.&lt;/p&gt;

&lt;p&gt;I have been unable to drink the TDD Kool-Aid, but I can see where it'd probably result in an improvement in some of my code for certain specific kinds of problems.  I'll probably try it out again next time I have to write a little library at work.&lt;/p&gt;

&lt;p&gt;This book is expensive and short, but the alternative for learning about TDD are half-baked blog posts, which is why I bought a book.  I don't know of a better book because this is the only one I have, and I'm unsure at this point whether I really want to buy another book on this topic.  But this book is highly recommended by many TDD &lt;del&gt;fanatics&lt;/del&gt; enthusiasts, so I don't know.&lt;/p&gt;

&lt;h2&gt;The Little Schemer&lt;/h2&gt;

&lt;p&gt;Next I read &lt;a href=&quot;http://www.ccs.neu.edu/home/matthias/BTLS/&quot;&gt;The Little Schemer&lt;/a&gt;.  The style of this book can best be described as &quot;cute&quot;.  Examples all use food, and it instructs you at various points to go make yourself a sammich (even leaving room in the book for &quot;jelly stains&quot;).  This somehow makes the topics, which can be rather intimidating, somehow less scary.  The book is very short, and not very dense (not many words on a page), but they somehow cram a lot of information into the book anyways, via the many examples.  It's a very focused and methodical book.&lt;/p&gt;

&lt;p&gt;This book goes through developing a simplified dialect of Scheme, with a focus on recursion and building up parts of the language from very simple primitives.  There are some neat little things along the way, like using s-expressions to represent numbers, and building up a full set of arithmetic functions using nothing but &quot;add 1&quot;, &quot;subtract 1&quot;, and recursion.  It'd be insane to do in real life because of performance, but it's really neat from a &quot;hey look what you can do, isn't this cool!&quot; point of view.&lt;/p&gt;

&lt;p&gt;The first half of the book is pretty simplistic (at least for me, with some basic knowledge of Lisp and Scheme), but the second half really starts delving into some crazy things, passing lambdas around to lambdas and writing evaluators and stuff.  But you almost don't even notice because of how solidly the foundations are built up to that point, and how well the examples are explained.  (You probably will notice once you hit the y-combinator, on account of your brains detonating.)&lt;/p&gt;

&lt;p&gt;This not a good book for &quot;learning Lisp&quot; in terms of learning the gritty details of to use a real-life implementation of Lisp.  But it's a good book for learning some of the concepts that make Lisp and functional languages powerful.   This is a very interesting and unique book, also highly recommended by many in the Lisp world.  I'm already planning to try &lt;a href=&quot;http://www.ccs.neu.edu/home/matthias/BTSS/&quot;&gt;The Seasoned Schemer&lt;/a&gt; next.&lt;/p&gt;

&lt;h2&gt;Real World Haskell&lt;/h2&gt;

&lt;p&gt;Finally I started plowing through the recently-released &lt;a href=&quot;http://book.realworldhaskell.org/&quot;&gt;Real World Haskell&lt;/a&gt;.  This book is freely available online, which is great.  It also allows readers to make comments on every paragraph in the book, which is a highly collaborative and probably very intelligent way to write a book, and also can provide insight for readers who don't understand the text at any given point.  I may buy a hard copy, I haven't decided.  (The online version has some FIXME notes and typos that I can only hope are fixed in the real thing.)&lt;/p&gt;

&lt;p&gt;I'm only up to chapter 11, but it's good so far.  It gives a ton of examples and goes slow enough for people completely new to Haskell to pick the language up.  And it includes some of the mechanics of compiling and/or running programs in &lt;a href=&quot;http://www.haskell.org/ghc/&quot;&gt;GHC&lt;/a&gt;, which is extremely helpful.  I did start getting lost around the time monads were introduced, but that's to be expected.  It usually takes me two or three good reads of this kind of book before I grok it all, which is no fault of the book.&lt;/p&gt;

&lt;p&gt;Haskell.  Last time I used it, I wrote Pong in Haskell in one of my college classes.  It was an immensely painful experience.  I'm going back to re-learn Haskell now because I find myself edging more and more toward functional languages and away from the C/Java world.  &lt;/p&gt;

&lt;p&gt;Haskell is far too much to swallow if you have no experience with functional programming, which is probably why I hated it in college.  (That said, a smarter person than I may have fewer problems.)  After graduating school, I got my first whiff of this world again via Perl's &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;grep&lt;/code&gt; and friends.  Then Ruby pushed it home for me with its widespread use of block parameters (lambdas in disguise).  And after learning Lisp (and especially later, Clojure) I can't live without higher-order functions.  If I had to write a classic for-loop and manually keep track of a counter variable I'd probably vomit at this point.  Haskell takes function manipulation to an even greater extreme, which I still haven't fully wrapped my head around, but I like what I've learned so far.&lt;/p&gt;

&lt;p&gt;Laziness is awesome, function currying is awesome, and this is the first time I've read about folding, apart from brief struggles with Ruby's (poorly named) &lt;code&gt;Enumerable#inject&lt;/code&gt;.  Pattern matching strikes me as vaguely similar to Common Lisp's / Clojure's destructuring-binding, which is one of the nicest features I've seen in any language when it comes to making a programmer's life easier.&lt;/p&gt;

&lt;p&gt;Maybe it's all just interesting because it's still new to me.  But I like the whole idea of functional programming.  I like the idea of functions that always produce the same output from a given input.  How and when to handle side-effects and object mutation is a problem that's always nagged at the back of my mind even when writing Ruby code.&lt;/p&gt;

&lt;p&gt;That said, Haskell still (at this point in the book) does not strike me as a practical or real-world language in the slightest.  You've got to jump through some crazy hoops to get a lot of things to work, especially when it comes to I/O.  The book describes how to write a pretty-printer, and how to parse a binary file, both of which require some acrobatics to write concisely in Haskell.  In particular the parser library lost me entirely; functions were being chained to functions in all directions and I couldn't follow it.&lt;/p&gt;

&lt;p&gt;I think one reason Java is so popular is that you don't have to be a genius to write it.  To write Haskell (or even Lisp) well, to take advantage of the language and use it smoothly, you really do need to do some deeper thinking.  The abstractions are more powerful and more &quot;abstract&quot;.  It's not too hard to understand a world made of objects with a bunch of knobs you turn via method calls.  Lambdas and recursive functions and monads and typeclasses are a more ephemeral thing.&lt;/p&gt;

&lt;p&gt;That said I plan to stick with the book.  Practice makes perfect.&lt;/p&gt;</description></item><item><title>TDD / BDD</title><link>http://briancarper.net/blog/tdd-bdd</link><guid>http://briancarper.net/blog/tdd-bdd</guid><pubDate>Fri, 29 Jun 2007 22:23:51 -0700</pubDate><description>&lt;p&gt;I have read the so-called rules of test-driven development.  As a rule, you are supposed to write tests first, run them and make sure they fail, then write the minimum amount of code to make your test succeed, make sure the tests pass, and repeat.  Long have I skipped this first part.  Running a test to make sure it fails before you write code that makes it pass, that is.  It always seemed redundant.&lt;/p&gt;

&lt;p&gt;Today for laughs I took an old module of mine and started it over from scratch and followed the above procedure.  A funny thing happened: some of the tests that I expected to fail actually passed without my having to write any code.  For example it turns out my class inherited a &lt;code&gt;:to_s&lt;/code&gt; method from its parent and that did exactly what I wanted, without my realizing it.  The end result after an hour or two was about 60% less code than the original module for a module that does exactly the same thing (i.e. passes all the original module's tests), and the code I ended up this time with probably works better.  It's certainly cleaner.  So maybe there's something to these magic rules.  We'll see.&lt;/p&gt;

&lt;p&gt;My theory of learning to program (or learning in general) is that there's always something new out there that I haven't found yet.  A lot of it is crap, but some very small portion of it is really good.  So I make sure to take some time every once in a while and read something completely alien to me, to test the waters.  And to keep things fresh.&lt;/p&gt;

&lt;p&gt;This week, it was &lt;a href=&quot;http://rspec.rubyforge.org/&quot;&gt;RSpec&lt;/a&gt; and &quot;&lt;a href=&quot;http://www.google.com/search?q=behavior+driven+development&quot;&gt;Behavior-Driven Development&lt;/a&gt;&quot;.  My buzzword detector went off at first, but it seems interesting.  The idea is to change the &lt;em&gt;wording&lt;/em&gt; used when writing unit tests, from something like &lt;code&gt;assert_equal X,Y&lt;/code&gt; to something like &lt;code&gt;X.should == Y&lt;/code&gt;.  The idea being that the latter terminology somehow helps you write tests that are more in tune with what TDD is supposed to be driving you toward: not testing after-the-fact, but rather building up a real programmatic specification for your code before or as you write it. &lt;/p&gt;

&lt;p&gt;There's more to the whole thing than that, obviously, but that's part that stuck with me.  It's a matter of language choice (not programming language choice, but class/method/variable name choice within some programming language).  Linguistics has always fascinated me, and I do think there may be some credence to the argument that a simple change in terminology can affect how people &lt;em&gt;think&lt;/em&gt; about a problem.  Word choice is a powerful tool. &lt;/p&gt;

&lt;p&gt;Whether this thing has any real value for writing good code is yet to be seen by me.  I am always a bit hesitant to drink the kool-aid.  RSpec itself is nice though.  It really shows off the power and expressiveness of Ruby, in how it works.&lt;/p&gt;</description></item></channel></rss>

