Fri, 23 Dec 2005
Canvas, Ajax, and the Supertrain
I've written a tutorial on how to combine canvas and Ajax. In this article I use canvas to graphically represent the real-time state of a fictional railway system (live example). Send me feedback if you have suggestions for improvements.
Thu, 22 Dec 2005
My take on Dynamic vs. Strongly Typed
Update: Dave Astels has alerted me that I am mixing some orthogonal concepts in this post. I'll leave the post as-is, but it looks like I'll need to hunker down and educate myself a bit more before I spout off about this stuff again.
I've followed a
of blog posts
that will probably spawn several more threads over the next few days and on into eternity as the conversations and debates over dynamic vs. strongly typed languages perpetuate themselves. This particular thread has not provided a compelling argument either way, but it does bring up some critical issues: 1) the safety provided by strong typing, and 2) the safety provided by strong testing.
I've been programming for 5 years. The first half of those 5 years was spent writing all sorts of Perl code. I remember people shaking their heads (in pity, I think) when they heard I was learning to program with Perl, and I always wondered why. I understand now. Dynamic languages like Perl are insanely powerful. It's like giving a Harley Davidson to a 16-year-old. They're going to do some damage: it's just a matter of time. And with Perl, I did some damage, but I also got it under control and began to use it responsibly.
And then I switched to Java. I was excited to learn Java because it had such a huge mindshare advantage over Perl (not per capita, but just by sheer numbers). I remember the strange constraining feeling of declaring types for the first time. It felt different, but I liked how explicit the code looked when I read it. It was comforting to use a compiler, and the IDE's were incredible!
At the same time I was teaching myself Java, I was beginning to practice test-driven development. Over the second half of these 5 years, I have come to value TDD as the most fundamental practice in my toolbox. It is an enabling practice that allows me to refactor mercilessly and evolve designs incrementally.
Over the last year I have had the opportunity to get back to my dynamic language roots. I've spent about a quarter of my time in Perl and Ruby. Coming back to dynamic languages I have observed two important phenomena: 1) I am suddenly interested in contributing to Open Source again, and 2) (Dynamic languages + TDD) == (power + safety) == confidence.
The comment that spurred me to write this post was from
Strong testing is fabulous, no doubt about it: the problem is that most developers don't have the discipline to write and update their test suites. The consequence is that, in the real world, there actually are benefits to static typing in complex projects. One way of thinking about static typing is as "just another test suite", except that it's a test suite developers are less likely be lazy about or subvert.
I couldn't disagree more, on so many levels. And comments like these speak volumes about the different perspectives we take as an industry. I currently live in the real world of a complex project written in a static langauge, and I observe daily what little difference that compiler makes in the face of a mountain of untested code. If you don't have the discipline to write tests for your software, then please stop writing software, and by all means, don't use dynamic languages. If people choose strongly typed languages because most of their developers are undisciplined, they've already lost. Paul Graham has more to
say about this.
I'll sign off with this thought from Justin and Stuart...
The "safe language" argument appeals to fear, while the "flexible language" argument appeals to a sense of opportunity and adventure. Both are powerful motivations, so for a long time this argument has been a stalemate. Happily, that period is coming to an end. Two new factors have come into play: automated testing and transparency. Over the next five years they will turn the balance totally in the favor of more flexible languages.
Thu, 15 Dec 2005
Canvas Creeping Forward
With the release of Firefox 1.5, I expect to see an increasing number of people experimenting with the canvas tag. The Ajaxians posted Romain Guy's cool Crystal CD case effect. Consider taking advantage of canvas and Ajax for real-time graphical data presentation. They're an awesome combination.
Mon, 12 Dec 2005
The Empty Cup
Despite my growing number of distractions (Ajax, Rails, Selenium), I still have at least part of my attention on the apprenticeship patterns. One of the nice things about writing about this stuff is that examples of the patterns are everywhere in a typical software project lifecycle. I wrote up an example of Expose Your Ignorance for my latest StickyMinds column:
The Empty Cup.
Fri, 09 Dec 2005
Selenium on Rails
Once again I find myself distracted from my writing. Last time it was Ajax, and this time it's the killer combination of Rails and Selenium. I've joined the Selenium project to help improve the dynamic language drivers. My first goal is to integrate "driven" Selenium with Rails. Last night I spiked it against a partially developed Depot.
Here's the test case:
require File.dirname(__FILE__) + "/seletest"
class ExampleTest < Test::Unit::TestCase
verify_text_present 'Listing products'
verify_text_present 'Price should be positive'
And here's a screenshot of Selenium driving Rails.
As I added to the number and complexity of test cases, I followed Brian's advice and moved to a more declarative style. I'll have more to say about this in the weeks ahead.