I’ve not touched Ruby yet, but I’m insatiably curious, so I talked to Darren about it.
As far as I can work out, dynamic languages in general are fantastic if you’re running Test Driven Design; because it’s not the compiler that tells you you’re wrong, it’s the tests. (I’ve never tried this with a dynamic language, but am looking forward to the experience.)
I have a bit of a problem with this idea, though. As much as I like to go on about “the right way”, in practice I’ve not yet seen a project where all the developers write tests for absolutely everything, however much they might like to. The temptation to “just hack that bit of code” seems to be too much. I think this is particularly true of project tools; those little scripts which lend themselves nicely to Perl or Ruby and which aren’t really part of the code base.
Does Ruby tend to encourage people to write tests for everything? Darren thinks not. I’ve certainly hacked a few Perl scripts together in the past; things which had ten line comments for one strange regular expression, or little scripts which made perfect sense to me then, but I couldn’t tell you what they did or how they worked today. They always grow; have you noticed that? I like to think I’m a bit more disciplined now than I used to be, but the idea of thousands of developers out there with another language that lends itself to hacking makes me uncomfortable. It’s like seeing a good friend try on a dress, asking, “Does this make me look fat?” and trying to work out how to tell her that really, it’s not the fault of the dress. Imagine the expression on my face. It’s the same one I’m wearing now (the expression, not the dress).
It’s not Ruby’s fault; I’m sure it’s a great language. I believe, though, that there’s another way to encourage people into the golden path of TDD, even full-on Agile. Ruby’s a relatively new language*, and from this outsider’s point of view, it looks as though it’s gaining a culture and a following all of its own.
Is TDD part of that culture? Do the manuals, forums, etc. for Ruby say, “If you use this language, you should consider reading more about Test Driven Design”?
Just curious… and lazy…
I have vague, unformed visions of a monster language which is absolutely bound to definitions and tests for the behaviour of each class. I have even more vague ideas of how to implement that. I have a better idea of how horribly unwieldy it might be. Back to JBehave…
Update: Thanks to commenters and to Steven, who wrote this illuminating post in response. I think I’m starting to grasp the “Rails” concept of Ruby on Rails – it’s a web development framework with integrated testing (thanks, Steven). Will have to get round to practicing this at some point. If nothing else, I’d love to get a feel for the speed of the TDD / dynamic language cycle.
It’s good to see a bunch of people being so enthusiastic about their work. Hope for the future.
* I’m told that my perception of Ruby as a new language is wrong; it’s been around for as long as Java, and unit testing is built into the standard library. Sweet.
I think this is why I would recommend you to start up with Rails rather than to just hack away directly in Ruby. With Rails you get a full framework for doing TDD for the all the tiers of your application (using integration unit testing, not isolation unit testing with mock objects). Well-documented, well-organized, easy to use, quick to learn, productive. Rails truly encourages you to do TDD. (It’s so easy to use, it generates the stubs for all your tests, you just write the test and run the script and it does all the work for you. Including managing test-data and so on. Veeery nice.)
Ruby is just another scripting language, use it as you like (with or without TDD).
— Jon Tirsen
1) jump on IRC and come talk to us (irc://irc.freenode.net/#ruby-lang).
2) Check out ZenTest for a simple system to analyze and audit your tests and code and help you get on your way.
3) Ignore the comment above by Jon about doing rails because it “truly encourages you to do TDD”. BZZZT. No, it doesn’t.
Ruby has a stronger tradition of TDD than Java. The unit testing framework is part of the standard library. DynaMock/JMock are Java ports of a Ruby mock object library that I wrote about 4 or 5 years ago (my memory is a bit fuzzy on exactly when I wrote it).
Also, I don’t know why you say that Ruby’s a relatively new language. It’s been around for 15 years or so, about the same amount of time as Java.
Rails is a framework for web development. It just happens to be developed by a group of folks that have integrated testing support in it.
Unit Testing is built into the standard library of Ruby, and as Anonymous pointed out, Ruby has a longer history of TDD.
I guess it’s the whole Rails hype that’s brought it out of the shadows. Thank you for correcting me (and congrats on being the instigator of a fine tradition, whoever you are).
Updated again. Cheers!