Archive for March, 2006

Uncategorized

Redmonk Radio gem

Listened to the third episode of RedMonk Radio on my way in today. My favorite bit:

Coté: There’s the evolution of, y’know, way back when the military radar system drove technology, right, and then there was NASA, and then it went into private enterprise, and now it’s kind of the consumer space that seems to drive everything.

James: Oh, Coté, you’re my man, I’m so glad you’re saying that. Let’s create games platforms to drive technology instead of war to drive technology. I am all about that. Consumer-driven innovation is the better kind. Let’s stop funding all the military stuff and fund fun that will drive technology.

Right on.

Uncategorized

On Method Calls and Messages

Rubyists talk about methods calls as sending message to objects, a notion that I understand is inherited from Smalltalk. It always seemed a little strange, but I could accept it as an odd quirk (“Bah! I understand method calls!”) and move on to writing code. This is unusual behavior for me, since normally I try to understand a language on its own terms. Now, though, I think I finally grok all this talk of messages, thanks to A Little Ruby, A Lot of Objects, an incomplete book in the style of The Little Schemer. And as it turns out, terminology matters.

class Dog
  def speak
    "Woof!"
  end
end

fido = Dog.new

Calling the speak method on fido (fido.speak) is really sending a message to the fido object. When fido receives the “speak” message, it knows to invoke the Dog class’s speak method. It answers, or returns, with the String “Woof!”

Yeah, that doesn’t seem too special, does it?

But here’s the thing. In Ruby, everything’s an object. 2 is an object of type Integer. 2 + 5 in Ruby is really saying, “Send the message “+” to the object 2, along with the parameter 5.” That is, 2 + 5 is convenient shorthand, syntactic sugar for 2.send("+",5) (which is, by the way, valid Ruby). 2 receives the message and invokes its + method, passing 5 as a parameter. It responds with 7.

Okay, this is still not seeming very special. Doesn’t this just muck up the discussion? Sure, it’s neat that 2 is an object, but what do you gain from all this talk of sending messages?

I’ll tell you where it finally clicked for me: polymorphism. I’m not sure why, but for some reason polymorphism is often a tricky concept for beginning programmers. Couched in terms of sending messages to objects, it’s crystal clear (at least to me :). You can send the same message to different objects, each of which will invoke the appropriate method of its class.

class Cat
  def speak
    "Meow!"
  end
end

garfield = Cat.new

With both fido.speak and garfield.speak, we’re sending the message “speak” to the object. fido receives the message and invokes its speak method, and garfield invokes its own speak.

+ does different things for Strings and Integers. This is commonly called operator overloading.

2 + 5 == 7
"Abe " + "Lincoln" == "Abe Lincoln"

The message is the same: “+” — but the methods are different. Ah ha!

And now I finally understand duck typing in relation to polymorphism. It should have been obvious earlier, but I never thought of it in that way (probably because I figured that polymorphism wasn’t that tricky, so I didn’t think about it). Dave Thomas’s explanation of duck typing is fairly clear. In Ruby, types are defined by what objects can do rather than their class.

When I write

  fred

in Ruby, I don't care whether fred is a String, a File, or an Array

What matters instead is whether fred can respond to the message “A Little Ruby, A Lot of Objects, let me make it clear now: it is a fine read, highly recommended. And now I want to go read The Little Schemer.

Uncategorized

Kiara’s MFA Reading

Kiara’s getting her Master of Fine Arts in Creative Writing from Hamline this spring, and will be reading from her theses this Friday. She blogs about that over at Wordspinning.

Yes, theses. Maybe it’s just considered one thesis, but she’s done thesis-length works in both poetry and prose. That’s Kiara for you: why do anything half-assed when you can do twice the amount of top-notch work?

It sounds like she’ll be reading “Mary’s Baby,” which is a fine, fine short story embedded in her novel. I’m excited to see how she reads that, as the narrative voices in the story are so strong and so distinct.

Uncategorized

JavaScript interpreter in Dashboard

The JavaScript shell is nice, but if you’re using OS X there’s a better option. On a tip from Todd Ditchendorf, I’m now running both a JavaScript and a Ruby interpreter in Dashboard, just a keystroke away.

It’s easy. Todd gives directions for installing WidgetTerm, which is key to the whole thing. Then drop a jar from the Rhino project in your Java classpath, set an alias to a JavaScript shell, fire up a WidgetTerm instance, and you’re done. It sounds more complicated than it is.

I need to pay more attention to Rhino. It caught my attention when I read this discussion of choosing a Java scripting language and saw how Rhino stacked up against JRuby, Groovy, Jython, and others. Here’s an obvious application.

Uncategorized

Missing lots of fun

No Fluff Just Stuff is in town this weekend and I’m missing it. Sigh. I have to make a more concerted effort to attend this sort of event.

Uncategorized

Feedburner

My RSS feed is on Feedburner now, so I am redirecting requests for the RSS there. If you use an aggregator, it should follow the redirect, but you might want to update to the new URL anyway.

Why Feedburner? Two reasons to start:

  1. It integrates my del.icio.us links into the feed, which is something I’ve meant to spend ten minutes doing myself but never quite got around to.
  2. It creates a pretty version with a style sheet. Something else I’ve meant to spend ten minutes doing but never quite got around to. Story o’ my life.

It will be nice to see some stats on the feed use, too, something I occasionally generate with a series of Perl scripts but don’t follow closely.

Java

It’s not always a good fit.

“So,” Tim asked, “still down on Java?”

When we had last spoken, I was reading Beyond Java, so that was an understandable question. I’ve had the conversation an awful lot lately and people keep being surprised by whatI say, so I figure it’s about time I write something here to explain my position.

Am I down on Java? Not per se. Java is not a language I generally enjoy working with, but I write web apps for a living. I do not believe that Java is an ideal choice for the work I do — I don’t even think it’s a good one. There are rays of hope: RIFE looks to be especially promising (hell, even exciting!) for making Java web apps far less painful than the norm. But by and large, the way I believe most people write Java web apps makes it a very unpleasant platform to work with. Unpleasant in the sense of slow and ineffective, with far too much code.

I’ve also been turned off by unbearably slow development cycles, which I cannot lay entirely at Java’s feet. Other factors like politics and methodology contribute. Still, in most people’s hands it takes longer to write something in Java, becaCan a team of experienced, solid developers work fast and well with Java? Of course. But most development teams are not filled with that kind of programmer.

If it works for you, great. I don’t think it’s worth anyone’s while to get into pointless language debates. But personally, I would rather use something other than Java for web apps, especially the whole JEE stack. My experience with J2EE has been barely manageable complexity in both development and operations management, which stands a good chance of making apps more difficult to maintain and secure. It is a good fit for some applications, when JEE serves to address and alleviate complexity in the problem space by providing simple solutions. Assuming that happens. :) I just don’t see web app control flow and presentation as being a hugely complex problem until Java enters the picture.

So what’s the alternative? Oh, there are plenty. Could or should Java play a role in our development? Of course. There’s often a reluctance to involve more than one language in an application stack to keep things “simple,” which I think is short-sighted. I often like to use more than one language for complex apps because it forces me to keep the design and APIs clean, a collection of loosely coupled services. Sometimes I like to use a full-stack framework, too. It depends. Use the best tools for the job. Leverage the strengths of the languages in your arsenal. Java fits well on the far back end, integrating legacy systems and managing interplanetary navigation. Closer to the front end of a web app, I’d use something a bit more suited to web development, like PHP. In the end, I think it would be faster to develop, easier and cheaper to maintain, and make developers happier. I try to be pragmatic and happy in my work.

Uncategorized

Pro::PHP Podcast: PHP on Windows

On the latest Pro::PHP Podcast, Marcus Whitney interviewed Microsoft’s Brian Goldfarb and Joe Stagner about PHP on Windows.

PHP developers may have already heard this interview (if not, why not? It’s a good podcast!). I wanted to be sure to mention it here because just as I think it’s useful and important for PHP programmers to separate the language from the LAMP platform and get away from knee-jerk reactions against anything having to do with “M$”, I believe that .NET developers should hear discussion from within Microsoft of non-Microsoft languages on their platform and how that might be a Good Thing. Good stuff.

I haven’t talked or written much about it, but I like a lot of what I see in .NET. Microsoft has done a far, far better job than Sun (or Oracle, or IBM…) at marketing to developers. I’m still not about to take much time to play around with .NET, since I don’t have a Windows box at home and have better things to do with my time at work, but it is compelling. I’ll probably watch some of the webcasts at learn2asp.net, and who knows? Maybe I’ll get Mono up and running on my Mac, although I think it’s too early for .NET 2.0 on Mono at this point, right?

Of course, first comes more Ruby, more PHP 5, then Smalltalk, Lisp, Haskell, Erlang… oh, and raising two kids. Do you see my problem? :)

Go listen to the interview.

Uncategorized

Troubleshooting IE

I spend far too much time explaining to my coworkers that no, Internet Explorer is not behaving correctly: that caching behavior is broken, that box model is not standard, that JavaScript behavior is unusual. Sometimes it’s not even that IE is wrong, it just chooses a different path than every other damn browser we test. Yet the expectation I confront is that if IE behaves a certain way, it is right and everything else is broken, so we should just tell people to use IE. Aargh! And best yet, it doesn’t matter that IE on my computer doesn’t behave the way it does on theirs, because IE on their computer does what they expect so I must have a nonstandard configuration. Grrr…

So it is with great relish that I read Amy Hoy on troubleshooting Internet Explorer. I’m pinning that to my wall, you can be sure.

Uncategorized

Selenium IDE

I’ve had Selenium on my radar for a while. Automating web app tests in a browser? Sounds great. FIT-style test definitions? Fantastic. Run it from JUnit? Wow! But I was always “too busy” and never got anywhere with it until I discovered Selenium IDE, a Firefox extension that can create and run Selenium tests. I watched this screencast, installed Selenium IDE, and was up and running in no time. I highly recommend it.

It immediately proved useful, as I discovered an intermittent bug in one of our web apps. Selenium IDE recorded my session on the web app, including a check for certain text that indicated the bug. I saved the test definition as an HTML file and attached it to the bug report. After I walked the developer through installing Selenium IDE and loading my test, she could run through it several times to finally trigger the bug. Bingo! I don’t think I’ll need more than that to sell the tool to the rest of my team.

Now I need to dig deeper and see what more Selenium can do for me. Also, take a look at Selenium on Rails.

Next »