This post originated from an RSS feed registered with Agile Buzz
by Glenn Vanderburg.
Original Post: No Thanks, I'll Stick With Ruby
Feed Title: Glenn Vanderburg's Software Blog
Feed URL: http://www.vanderburg.org/cgi-bin/glv/blosxom/Software?flav=rss
Feed Description: Glenn Vanderburg's blog about software development
Ted Neward writes about Microsoft's Monad shell
language, extolling its coolness ... which is fine, except that he
goes wildly wrong by titling his post "Need Ruby? Nah -- get Monad
instead".
Ted, my friend, thou doth protest too much, methinks. Pointing out
cool technology is fine (and to some degree I agree that Monad is
cool) but when you make a comparison like that, you have to back it
up. And in this case, Monad falls woefully short, by your own
criterion.
Here's my Ruby version of your Monad "get-answer" script:
#!/usr/bin/env ruby
require 'open-uri'
require 'cgi'
fail "Please ask a question." unless ARGV.size > 0
question = ARGV.join(" ")
query = "http://search.msn.com/encarta/results.aspx?q=#{CGI::escape(question)}"
page = URI(query).read or fail "Couldn't get response."
puts
if page =~ %r{<div id="results">(.+?)</div></div><h2>Results</h2>}
response = $1
response.gsub! %r{<\s*a.*?>.+?</a>}, "" # remove links
response.gsub! %r{</(div|span)>}, "\n" # insert newlines
response.gsub! %r{<.*?>}, "" # remove tags
puts response.squeeze("\n").rstrip # collapse adjacent newlines and trim whitespace
else
puts "No answer found."
end
Sorry, Ted, but I think that's far better than the Monad version. And
you do, too. Just a month ago, you wrote this:
While speaking at a conference in the .NET space [...] Rocky Lhotka once offered
an interesting benchmark for language productivity, a variation on the
kLOC metric, what I would suggest is the "CLOC" idea: how many lines
of code required to express a concept. (Or, since we could argue over
formatting and style until the cows come home, how many keystrokes
rather than lines of code.)
Leaving aside the fact that this is a very old idea, I agree that this
is a mostly valid measure of language power and productivity (although
I prefer to measure it in syntactic tokens, as Paul Graham
does). And Ruby is clearly the winner.
Ruby: 17 lines, 76 tokens
Monad: 37 lines, 217 tokens
Plus, my Ruby version will work on my Mac, your Windows machine (even
pre-Vista), Linux machines, my OpenBSD server, and those nice Ultra
machines that Tim Bray is so kindly directing to worthy projects. So Ruby is more powerful in another
dimension as well. (True, you would have to install Ruby separately
on some of those systems. I'm so glad Apple doesn't suffer from NIH
syndrome as much as Microsoft does.)
Don't get me wrong -- as a Windows shell language, and especially one
built into Windows and supported by Microsoft, Monad is very cool, and
a vast improvement on anything they've ever produced in that space.
But it looks like Microsoft still missed some lessons, even in that
restricted space.
There was a time when many serious systems were built as shell
scripts, and even batch files. But in these days of serious scripting
languages like Perl, Python, and Ruby, I can only think of one reason
to write a substantial bulk of code in a shell scripting language like
Monad, and that's if you absolutely have to know that it will run
without requiring a separate software installation. Shell languages
have to walk this awkward line between terseness for convenient
command-line use, and the constructs necessary for serious
programming, and that makes them inherently awkward for the latter
task. These days, shell languages are mostly useful for ad
hoc on-the-command-line throwaway programs, and what I've
seen of Monad tells me that it's a little too strict and verbose for
that job.
I do think Monad might have one seriously great effect: it might teach
Windows developers the importance of designing utility programs with
an eye toward cooperating with other programs in a scripting
environment. But I don't see it displacing Ruby, Python, or Perl
anytime soon.
As for Ruby in particular, I think Edd Dumbill said it
best:
... the subtle elegance of the Ruby idiom is a slowly appreciated and
highly satisfying flavour.