Mobile data access in Canada

Thomas Purves has written about how badly we’re being screwed for data access by our three mobile operators in Canada, and many people agree. He’s completely right, mobile data access is way too expensive to be generally useful. Even SMS is expensive at $0.15 (increased from $0.10 after our five carriers consolidated down to three).

I make do with a wi-fi-enabled mobile phone, but unfortunately wi-fi is not really a viable mobile alternative. Open hot-spots are few and far between (or offered by the same three amigos and priced so as not to compete with their mobile data). I’d happily pay the flat $29/month for Toronto Hydro’s OneZone, but I’m rarely inside the coverage area and it’s (by many accounts and in my own personal experience) barely usable anyway.

Canada is a great place to live for many reasons, most of which are more important than wireless data access. But the rest of the world is at the beginning of a mobile internet boom that Canadians are generally not taking part in. Who knows how many more would-be entrepreneurs from our flourishing local tech scene might be developing innovative mobile apps if they only had the opportunity to be inspired? It’s no wonder all the innovation in the mobile space comes from elsewhere.

Facebook scales!

I’m really impressed with Facebook. It’s fun (totally addictive in fact), and I think it’s actually a better way to keep in touch with friends than email.

But what I’m really impressed with is how well they’re handling a massive growth in traffic. As of Feb 23 they’ve gone from zero to almost 18 million users in just over three years, an increase of 240% since last July alone.

From the Facebook blog five weeks ago:

…almost ten million different users sign into the site every day, or more than half the user base. During our biggest peaks - Sunday & Monday night around 10EST - more than one million people will be simultaneously logged into the site.

Friendster is famous for missing a huge opportunity in part because of poor performance (40 second page load times), and MySpace’s well-known and frequent reliability problems have continually frustrated their users.

According to Alexa (as of today, April 11) Facebook’s traffic is only slightly higher than Friendster’s (who have since redesigned their architecture), and still far behind Myspace’s. (Alexa’s stats may not be that reliable however.)

Regardless of the actual numbers, they’re obviously doing the right things to keep on top of the massive growth so far. Unfortunately though, I haven’t been able to find out many technical details except that they have two terabytes of RAM used by memcached.

UPDATE April 16: Apparently their traffic increased by another 50% during the month of March! (Link via Matthew Burpee on Facebook).

Announcing GigPark

I’m excited to announce that I’ve joined a new venture, I’ll be leading the development for GigPark!

GigPark is a new service that will help you recommend your favorite service providers to friends and family, instantly get service recommendations from people you trust, and build your service business through word-of-mouth. Excited yet?! Me too!!

GigPark Logo

Please check out the GigPark blog for more information.

Process XML in Java more easily by… not using Java?

Java and XML are like peanut butter and chocolate, right? They just go together, don’t they? Jon Bosak of Sun summed it up most famously as “XML gives Java something to do“.

XML gives Java developers something to do
I think I see Sun’s master plan: the more work Java developers must do to solve a given problem, the more of them we’ll need to have. The more Java developers we have, the more popular Java appears. (The only problem left to solve is how to profit from that, but I digress). The key to this plan’s success is lack of syntactic support for XML, and the added bonus is that even more developers will occupy their time building endless numbers of libraries! “Why make trillions when we can make… BILLIONS?!” :-)

There are some decent libraries for handling XML in Java, but most are quite heavyweight, requiring you to create Java classes (in the case of the XML binding variety) or at least a config file (XML-based, naturally!).

There is another way
I’ve written before about using other languages with Java, and Groovy has some really nice features for handling XML. Groovy compiles to Java bytecode so you can write an XML handling class in Groovy and use it within your Java app. Here’s an example that uses Groovy’s GPath to read in an XML file from Sun’s XML DOM tutorial, and prints some of the elements. Just for fun, we’re loading the XML file directly by http:

def slideShow = new XmlSlurper().parse("http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/dom/samples/slideSample01.xml")
println("slideshow author attribute: ${slideShow['@author']}")

def slides = slideShow.slide
for (slide in slides) {
    println("slide title element: " + slide.title)
    for (item in slide.item) {
        println("  item text: ${item}")
    }
}

Here’s the Java version as a comparison. Honestly, nobody really uses the DOM API because it’s so painful (hence the existence of so many libraries to do the job), but this is the out-of-the-box Java way:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
URL url = new URL("http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/dom/samples/slideSample01.xml");
InputStream stream = url.openStream();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(stream);

Element rootElement = document.getDocumentElement();
String author = rootElement.getAttribute("author");
System.out.println("slideshow author attribute: " + author);

NodeList slides = rootElement.getChildNodes();

for (int i = 0; i < slides.getLength(); i++) {
    if (slides.item(i).getNodeType() == Node.ELEMENT_NODE) {
        Node slide = slides.item(i);
        NodeList slideChildren = slide.getChildNodes();
        for (int j = 0; j < slideChildren.getLength(); j++) {
            Node child = slideChildren.item(j);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                if (child.getNodeName().equals("title")) {
                    System.out.println("slide title element: "
                            + child.getTextContent());
                } else if (child.getNodeName().equals("item")) {
                    System.out.println("  item text: "
                            + child.getTextContent());
                }
            }
        }
    }
}

I have omitted error handling.

Using XPath in Java can make our job easier when it comes to searching a tree for a node (you wouldn’t want to see this done with pure DOM manipulation!), but we’ll still still have to deal with an org.w3c.dom.Node object that is the result:

XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "/slideshow/slide[title = 'Overview']";
Node overview = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);

Here’s the same thing done in Groovy, a simple one-liner:

def overview = slideShow.slide.find { it.title == "Overview" }

Two interesting things here are the use of a closure, and the use of == which might look wrong to a sharp-eyed Java programmer. Groovy uses == for equality and the method is() to test for identity. This is the opposite of Java but leads to more readable code because typically we compare for equality much more often than identity. And == works with null in Groovy, so your typical Java comparison (x != null && x.equals(y)) becomes x == y in Groovy, which looks more like what we mean.

Creating XML is also easy in Groovy using MarkupBuilder, here is the code to create our sample XML file:

def doc = new StreamingMarkupBuilder().bind {
    slideshow(title:"Sample Slide Show", date:"Date of publication", author:"Yours Truly") {
        slide(type:"all") {
            title("Wake up to WonderWidgets!")
        }
        slide(type:"all") {
            title("Overview")
            item("item") {
                mkp.yield("Why ")
                em("WonderWidgets")
                mkp.yield(" are great")
            }
            item()
            item("item") {
                mkp.yield("Who ")
                em("buys")
                mkp.yield(" WonderWidgets")
            }
        }

        mkp.yield("normal text here")
    }
}

System.out << doc

It’s easy to read because it has a visually similar structure to the XML that it’s creating, and the syntax is quite terse. Groovy has similar builders for other things besides XML, for example to create SWT and Swing UI’s. You can even create your own. More on how this is implemented coming soon…

There are other choices besides Groovy, of course, I haven’t tried it yet but Scala looks like it might be a good choice. (For that matter there are other choices besides XML!)

Google TTC Map

Ian Stevens has created a really nice Google Maps-based TTC Map. There are a lot of good Toronto-oriented Google Maps mashups, but for me this is one of the most useful. That and beerhunter.ca of course!