Archive for February, 2006

Book review: Programming Ruby

0974514055.01._AA_SCMZZZZZZZ_.jpgProgramming Ruby, by Dave Thomas.

I finally decided to review this book, having read it quite some time ago. The reason I waited this long is that I feared I wouldn’t have been able to provide a fair assessment of the merits of this book. My problem is that, nowadays, I get easily bored reading yet another programming book. And a book entirely dedicated to a single programming language was bound to bore me infinitely.

That’s what happened, actually. I got so bored that it took me a really long time to finish it, even after skipping entire chapters. I managed to finish it only because I forced myself to do it.

I know Ruby is cute, and has lots of nice and innovative features, but I just can’t stand anymore reading operator precedence tables, variations on the basic control structures and core libraries. Last time I got excited by a programming language was with Java, and that was circa 1995. I’m too old for that.

But I must try to stay objective and think how useful “Programming Ruby” could be to a young programmer and I have to admit the answer would be: a lot! As is customary with titles from The Pragmatic Programmers, quality is very high, both from a content point of view and from a presentation one as well. Well written, it even manages to inject a bit of humor into a dry subject. If you want a one stop shop reference for all Ruby, that’s it! Not much more to say, except that I’d have liked, at times, the code samples to be longer, more structured and less contrived, but it’s a minor nit.

I suggest that you read it in bits and pieces, not cover-to-cover and if boredom gets you, you can always get a little of why’s (poignant) guide to Ruby as an antidote.

It just doesn’t matter

I’m fairly behind on my reading list, as the last two months have been quite busy. I have a few thousand unread messages in various folders, but I’m not worried, as all of them are from some open source project’s mailing lists and I can just “mark all messages as read”. They just don’t matter.

Speaking of things that just don’t matter, while going through my feed aggregator’s backlog (517 unread entries right now and barely managing to read, or mark as read, more old items than new items coming in) I found this great quote by Jason Fried:

Most of the time you spend is wasted time on things that just don’t matter. If you can cut out the work and thinking that just doesn’t matter you’ll achieve productivity you’ve never imagined. It’s there if you just don’t pay attention to the things that don’t matter.

Nuff said.

Imogen Heap

Where are we?
What the hell is going on?
The dust has only just began to fall
Crop circles in the carpet

These are the opening lyrics to Imogen Heap’s “Hide and Seek”. I found them while looking for the title and artist of a recent Skoda commercial. So, if you were wondering the same, here’s the answer.

Oh, by the way, the girl also has a blog.

Technorati Favorites

You might have noticed that since a few days ago, I’ve been sporting a new button in the right column:

Add this blog to my Technorati Favorites!

While Technorati Favorites looks like a nice feature, it will probably end up with A-listers favoring other fellow A-listers and us poor Z-listers getting no traffic at all :(. So, if you want to help this Z-lister become more of a Y-lister or X-lister, could you click on the button and add this blog to your favorites, pretty please? I promise I will reciprocate. We need to be more helpful towards each other, if we want to overthrow the top-100 cabal ;).

One problem with this schema is that it’s not currently possible to know if you’ve been put on someone else’s favorites list, unless he tells you.

Update: It is now possible to see the 100 “most favorited” blogs on Technorati. As of now, #100 is Gawker, which has been “favorited” (is this even a word?) by just 11 people, so it shouldn’t be too hard to get into this special A-list. Since anyone can nominate at most 50 favorites, we can make a posse of 50 bloggers who favor each other and get everyone near the top of the list very quickly. If you want to join, just add my blog and all the others on my favorites list to your favorites and let me know.

Technorati Tags: , ,

Ruby for Java Programmers, Part V

If you’ve been following the previous articles in this series (Part I, Part II, Part III and Part IV) but are not yet satisfied with the range of solutions I presented for calling Ruby code from Java, here’s another one for you.

This one involves running your Java code as a separate process and interacting with it using some form of Web service (XML-RPC, SOAP or a RESTful service). We’ll use XML-RPC for this sample, mainly because it’s very easy to set up and use. You’ll need Apache XML-RPC version 2 to make the code run. Here’s the java code:

public class RPCFetcher {
    public static void main(String args[]) throws Exception {
        WebServer server = new WebServer(8080);
        server.addHandler("$default", new RPCFetcher());
        server.start();
    }

    public Vector fetch(String url) throws Exception {
        URL feedUrl = new URL(url);
        FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance();
        FeedFetcher fetcher = new HttpURLFeedFetcher(feedInfoCache);
        SyndFeed feed = fetcher.retrieveFeed(feedUrl);
        Vector items = new Vector();
        for (Iterator it = feed.getEntries().iterator() ; it.hasNext() ; ) {
            SyndEntry entry = (SyndEntry) it.next();
            Hashtable map = new Hashtable();
            map.put("link", entry.getLink());
            map.put("title", entry.getTitle());
            map.put("publishedDate", entry.getPublishedDate());
            items.add(map);
        }
        return items;
    }
}

Compared to the previous samples, there’s not much else you need to do, besides creating an instance of WebServer to handle incoming HTTP requests and dispatch them to the appropriate method. However, you need to convert your Java types to something that XML-RPC is able to understand, i.e. strings, numbers, dates, Vectors, Hashtables and little else.

The Ruby client code is much simpler:

require 'xmlrpc/client'
server = XMLRPC::Client.new 'localhost', '/', 8080
entries = server.call('fetch', 'http://agylen.com/feed')
entries.each do | entry |
  p "#{entry['publishedDate'].to_time} #{entry['title']}"
end

Possible drawbacks of this technique are the necessity of having a separate process running and the overhead of HTTP communication and XML-RPC protocol encoding and decoding.

Thanks to Nick Stuart and Erik Hatcher for laying down the basics.

Edgeio

img-logotop.gifToday edgeio finally launched. I was thinking of putting my PowerBook up for sale, but I have it on lease and the contract hasn’t expired already. I think it will in March, then I’ll be able to redeem it and sell it. At the moment, I only see one listing for a PowerBook, at $800. Mine is actuallly much better, at 1.25GHz, running OS X 10.4, no missing keys and an almost-new battery. I wonder if I’ll be able to sell it for $1000, but somehow I doubt it.

Technorati Tags:

Cocoon supports Ajax

Ajax v. InterNo, I’m not referring to Ajax as in Asynchronous Javascript and XMLApache Cocoon has actually been supporting Ajax for quite a long time — but to Ajax as the football team from Amsterdam.

The reason why I’m putting Cocoon supports Ajax in the title of this post is that yesterday a bunch of Apache Cocoon developers (including three committers) went to the Amsterdam Arena to show their support for the home team in the Champions League football match against Inter F.C.

(If you thought that I, as an Italian, should have supported Inter, think again.)

Ajax, with a young and unexperienced lineup, started off briskly and hit Inter twice, with Huntelaar and Rosales in the first 20 minutes. We were cheering together with the other 49,000 people at the Arena, but our enthusiasm lasted only until the beginning of the second half, when Stankovic scored a lucky hit and then, just four minutes before the end of regular time, Julio Cruz (ex-Feyenoord) equalized for Inter from a short distance, thanks to an illuminating pass by Figo and then Cambiasso.

All in all, it was a nice match but I think Ajax has little hope of going through, having to win against Inter in Milan in two weeks: hardly probable. I also managed to shoot a fair number of good photographs (including two of the goals) and finally resolved to upgrade my Flickr account to “pro” level in order to be able to upload most of them. You can see the results in my Ajav vs. Inter set. I must say that my Panasonic DMC-FZ20 performed very well, thanks to its long zoom lens and incredibly useful image stabilizer.

Technorati Tags: ,

Circlemakers

After my post from yesterday about crop circles, Jeremy told me that he actually knew one of the people who make crop circles in England. They even have a website: Circlemakers. Check out the pictures, some are hilarious, like the one I copied here, also as an homage to the Turin Winter Olympics.

olympic crop circles.jpg

Technorati Tags: ,

Crop circles from the satellite, and people too

CropCircle.jpgIt doesn’t matter whether you believe crop circles are made by alien intelligences or are just pranks, it’s indisputable that sometimes they are real works of art. Now the fine people at Google Sightseeing have started collecting images of crop circles as they can be seen on Google Maps. Cool stuff!

On a related note, Antonella Pavese is collecting Google Maps pictures where people are visible, in the 2006 Google Earth Census. Until recently, the world as seen from Google Maps/Earth seemed eerily uninhabited, as if some mysterious epidemic has swept it empty of all human life, just like in some sci-fi movie. But recently, with the increased resolution made available by Google, it has been easier to spot people on satellite pictures. I wonder if, in the future, resolution will become so hight that it will be feasible to actually recognize some of those people. Scary, huh?

(Via Davide.)

Technorati Tags: , , ,

Krugle

krugleIt might be a bit early to say something interesting about krugle, given that it hasn’t launched yet, but I’ll try.

Judging from the product brief alone, it should really rock. But of course, all that matters is execution. I think relevance can be a big issue here. One of the screenshots shows search results for “java hash map”. How do you decide that a search result from Eclipse is more relevant than a search result from Apache Portals?

Koders has the same problem here, though. However, searching for “java hash map” is not very meaningful: Any competent Java programmer would just use a java.util.HashMap. It would be more useful to search for, say, “red-black tree algorithm in java”. There Koders fails miserably, whereas Google does find some results which seem relevant. How will Krugle fare? I don’t know, but if I manage to be accepted in the beta program, I will surely report.

I have also some reservations about the emphasis on componentized software:

The world has shifted from inflexible, monolithic applications written in isolation to applications built with components that can easily be modified and leveraged.

Unfortunately, at least in my humble opinion, the promise of reusable, modifiable components has failed to materialize so far, except maybe for VB programmers. It’s true that you can find many freely available libraries, toolkits and frameworks, but try to find an application-level component that you can readily reuse without extensive rewriting and you’re suddenly faced with a much harder task.

Anyway, this shouldn’t detract from the fact that a search engine for Open Source code can actually be useful, if properly implemented. I’m currently thinking whether it would be possible and worthwhile to mash up The Open Source Zone with Krugle. Do they provide an API?

Last but not the least, they have Chris Locke on board as “Blog Wrangler”. Well, this probably shows that they have a clue, at least. ;)

Technorati Tags: , ,

Hippo Booze Cruise

What happens when you put a bunch of geeks on a boat floating on Amsterdam’s canals, in front of lots of wine and beer? Hippo Booze Cruise, that’s what!

Amsterdam bridge

Will Apple Adopt Windows?

John C. Dvorak: “Apple has always said it was a hardware company, not a software company. Now with the cash cow iPod line, it can afford to drop expensive OS development and just make jazzy, high-margin Windows computers to finally get beyond that five-percent market share and compete directly with Dell, HP, and the stodgy Chinese makers.”

It might be true that Apple has always been a hardware company, but it’s mostly the software (i.e. OS X) that makes me buy Apple computers. If I had to run Windows on my machines, why not buy a Sony Vaio instead of a MacBook? Or I would probably run Linux instead.

ApacheCon EU 2006 - Dublin, Ireland, June 26-30

Bertrand Delacretaz: “The ApacheCon Planners are pleased to announce that ApacheCon Europe 2006 will be held in Dublin, Ireland, at the Burlington Hotel, June 26-30.”

Hmmm, back to back with the RailsConf, which will be held in Chicago from the 22 to the 25 of June. I wonder if there are direct flights from Chicago to Dublin.

Campfire and AJAX making the web run faster, again

What David Heinemeier Hansson writes today links together the two latest posts I made here:

We’re currently polling every three seconds for every user active in a chat and while we’ll soon be able to regulate that between three and thirty seconds (depending on how active the chat is), it has certainly presented us with ’special needs’.

Exactly. As I wrote yesterday:

A second downside is that AJAX makes it really easy to write web pages that can hog a server much more than a traditional template processing step will ever be able to do. I can already see AJAX widgets constantly polling servers for updated data (news tickers, etc.) and possibly keeping server sockets tied for a long time, which is a usage pattern that most servers were not designed to cope well with.

So much for making the web run faster.

However, even with all this polling going on, Campfire is quite snappy and responsive. It’s really like IRC in a web browser, done right. I’m particularly intrigued by how they managed to have the browser window scrollbar scroll just the chat transcript and not the whole page. Brilliant! This is an application that really sets a new standard for web-based applications.

Campfire

campfirelogo.gifThe fine folks at 37signals have released another one of their nice, ajaxy, web-2.0-ish, ruby-on-rails applications: Campfire. Campfire is a web-based, group chat for businesses and it looks real cool.

I’m currently test-driving it and if you want to join my room for discussing Open Source, Web stuff, business opportunities or the weather in Amsterdam ;) click here.

Update: with just four available access slots in the trial version, it will be difficult to come in. Moreover, it also looks like if you close your browser window, you’ll still figure as online, thus occupying one of the slots apparently forever…

Updated update: looks like idle users get thrown out in about 90 minutes. It would be great if this interval were configurable, but at least it’s there. Good.

Technorati Tags: , , , ,

AJAX is making the Web run faster

A very interesting article by Tim Bray on the real benefit of AJAX:

I suspect there’s a huge system-wide optimization waiting out there for us to grab, by pushing as much of the templating and page generation work out there onto the clients. In particular, when you’re personalizing a page, assign all the work you can to the personal computer sitting in front of the person in question. Yeah, that cool, responsive AJAXy stuff is nice but maybe it’s the icing on the cake; the real win is making the Web run faster.

That’s mostly true, but I suspect there are some downsides as well. The most obvious one is that not all browsers are AJAX-ready and if you want to cater to those, you’ll have to go through hoops in order to provide people using them with the same user experience level, which will probably complicate your life as a programmer just a little bit.

A second downside is that AJAX makes it really easy to write web pages that can hog a server much more than a traditional template processing step will ever be able to do. I can already see AJAX widgets constantly polling servers for updated data (news tickers, etc.) and possibly keeping server sockets tied for a long time, which is a usage pattern that most servers were not designed to cope well with.

Greg Wilkins wrote about this issue some time ago:

But there is a new problem. The advent of AJAX as a web application model is significantly changing the traffic profile seen on the server side. Because AJAX servers cannot deliver asynchronous events to the client, the AJAX client must poll for events on the server. To avoid a busy polling loop, AJAX servers will often hold onto a poll request until either there is an event or a timeout occurs. Thus an idle AJAX application will have an outstanding request waiting on the server which can be used to send a response to the client the instant an asynchronous event occurs. This is a great technique, but it breaks the thread-per-request model, because now every client will have a request outstanding in the server. Thus the server again needs to have one or more threads for every client and again there are problems scaling to thousands of simultaneous users.

To sum it up, I have some doubts that having a server process a large number of small requests will be more efficient than having it process a dynamic template, given that you can often design your dynamic pages to be cache-friendly and put a fat, reverse proxying cache in front of the server. Edge Side Includes are also promising in this respect.

What Tim is doing on ongoing is fine, but the potential for abuse by less cautious web developers is high.

Google speaks Ruby (on Rails)

measuremap.gifDavid Heinemeier Hansson: “MeasureMap just got bought out by Google. I believe that’s the first Ruby on Rails application to be picked up in a Web 2.0′ish buyout. And it didn’t even have to launch, take that Yahoo! Speaking of, I’m now having a sale of futures in ideas for apps that I haven’t even thought of. Who’s bidding?”

Picture me envious! Here’s hoping that my Ruby on Rails application is the second one to be picked up. Yahoo! are you listening?.

Now, more seriously, Google will probably need some Ruby programmers soon so, if you have any experience, it’s maybe time to polish up your resume and send it to Google Jobs.

Last, if Measure Map is as good as they (the lucky few beta testers) say, I hope they move to an open beta soon. I don’t dislike Analytics too much, apart from the lagging issue, but having a more blog-oriented tool would rock.

Technorati Tags: , , , .

Scalability matters

Fancy going to the Turin 2006 Winter Olympics? Think again, as you won’t probably be able to buy tickets online, since the official ticketing website has been showing the following message for a few days:

Welcome to the Official Torino 2006 Ticketing website

ATTENTION: This site is actually busy, too many users are now connected.
Please try again in the next minutes.
Thank You.

In the meantime, you can content yourself with some photos, videos and podcasts from Cafe Olympic.

Update: just a few seconds after I posted this, the website started working again. We’ll see if it lasts, I guess.

Getting that Passion Back

I really dug this post by Berin:

In fact, part of what causes me to get going is the mission to make stuff that enables users. Things that let them do what wasn’t possible before. Learning new tricks and applying them to old problems. Solving new problems, etc. Bottom line is that my days in corporate life are numbered. I am going to make stuff that rules, and I plan on making money doing it. I am going to have a job that encourages innovation — even if I have to create it. That’s what keeps my fires burning now.

Indeed, passion is what prompted us to start SourceSense. We want to make innovative stuff that makes users happy. And of course, if we make money doing this, we won’t complain ;).

While I’m on the subject, I want to remember everybody that we have a contest running and you still have plenty of time to submit your works of art and possibly win a MacBook Pro. We already received a fair number of submissions: Some good, some less so, but if you want to make our choice harder, keep ‘em logos coming!

Brrreeeport

Everybody say brrreeeport, please.

Ah, the things you wouldn’t do for just one more bit of traffic ;).