Tom Morris

15 August 2010

A pungent mix of programming, philosophy, pedanticism, procrastination, perplexity, peripheral political polemic, and platters of preposterousness.

Do your own plumbing

I finally got around last night to replacing a load of Rube Goldberg code with some clean code.

And I just want to say: screw The Cloud. Write your own code. And if you can’t write code, the cloud won’t save you - you’ll still need to learn to code because visual programming tools just suck.

A while back I wanted to take an RSS feed and put it into Twitter. That’s easy, right? There are a bunch of services that do that with names like “twitterfeed” and so on. You take the RSS feed and give it to that service and let it do its thing. One less piece of code that you don’t have to maintain, one less box to keep running.

Trust me. It doesn’t work. Because the Twitterfeed-type services don’t let you do much in the way of customisation. They just take the title and the description, shorten the link and post it. So, what if the feed doesn’t quite fit that? Well, then, in the Cloud Computing magical scenario, you feed it into another service that does some kind of transformation on it. Like, oh, Yahoo! Pipes. That’d do the job.

Yahoo! Pipes is a wonderful service for many use cases, but if you are a programmer, you’ll hit the limits really quickly. You’ll hit the inherent clumsiness of the visual programming environment first - because you are working with very high-level functions that have been designed in a way that doesn’t exactly gel with how you think. Yes, you get a filtering function, and you get some other stuff. But you don’t really get a proper map function, meaning you can’t really transform the feed into something else. You don’t get low-level conditionals. You can emulate some of the things you want to do in Yahoo! Pipes by creating all sorts of bizarre and byzantine pipe structures. You end up with a screenful of blobs with wiring that would make a network engineer blush.

So you hack together the thing you are working on, and push it over to the Twitterfeed service. Only they handle RSS feeds strangely - they do fancy stuff with GUIDs. (Side-note: I don’t understand why we need GUIDs on the web. We have a globally unique identifier - it is called a damn URI. Use that, damnit.)

So it is late, and you hack it together by having a Ruby script that pulls in the feed from Yahoo! Pipes, runs a damn regex over it to pull the element you don’t want out and pushes it back out. Well done, you have avoided writing code by creating a Rube Goldberg machine.

The data goes like this:

Original site to Yahoo! Pipes to your machine to your server to Twitterfeed to Twitter.

This is barmy. And why did I do this? Because I wanted to avoid writing some code.

Like all Rube Goldberg machines, entropy took over and the thing broke a few weeks later and stopped tweeting.

I finally got around to rewriting it. It was really painful to do. It ended up being 61 lines of Ruby. That wasn’t very hard, was it? Now the data flow is this:

Original site to my machine to Twitter.

Really, what was the point of this silliness? To avoid having to write some code? That’s not a very good reason, is it?

I mean, seriously, we have these tools to avoid a bit of programming for non-programmers. But the end result is one where you are relying on so many servers to keep doing what you expect them to do without problem. Well done Web community, we now have ways for non-programmers to make shockingly brittle pseudo-code. You also don’t get abstraction easily: you can’t really write functions or classes to abstract common patterns. You just get to reimplement them over and over again.

What else don’t you get with the “stick the code on all these interlocking services” approach? Logging. Debugging. Unit testing. Open source libraries. In the above linked example, I can see myself wanting to add logging (so I can just chuck in Log4R). I also will probably add a thing to verify that the XML has actually downloaded properly and retry if it didn’t work, and stick in a better time handling routine - so that it immediately logs the last successful download and then uses that, so we don’t get any missed updates. I do a lot of this kind of feed mangling, and it’d be pretty simple to abstract out some of the common patterns. This is basically what Pipes has done. But the problem is that even if you abstract out the common patterns, you still need everything else in the language!

I haven’t got a problem with services like Yahoo! Pipes, but don’t use it for anything beyond prototyping and very simple hacks. Once you’ve got more than about four action blobs on screen, close the tab and write some code. If you don’t know how to code, learn. It is now easier to learn to code than at any time in the past. And there are more than enough places to host your code: on your own computer, on a VPS or on services like App Engine or Heroku. Even a cheap PHP hosting account will do the job. And, damnit, publish your source code. Go through and pull the passwords and API keys out and replace them with “SECRET” and put them up. That way others can take a look and make suggestions on how to improve the code.

Visual programming tools have been tried so often. If you want to remix data, code is the most viable way of doing it. Learn to code. If you want to mangle data, you’ll be less stressed if you have full control over what is going on, rather than blind faith in a bunch of web services to do the right thing.

Station Approach, Tunbridge Wells, TN1 1

Notes on Play from LSUG

Just archiving my tweets from the London Scala User Group this week: @vigosun gave a talk about Play and this is what I had to say.

@vigosun is coming from PHP: standard Java frameworks (Spring) not welcoming. [tweet]

play is not the “traditional JEE stack” [tweet]

Play is a platform, “not just a glue framework”. “Usability first”! [tweet]

Play features: stateless, RESTful, no-compile, efficient error reporting, built-in test framework, templates [tweet]

In short, Play is everything that makes Rails cool but for Java and Scala. [tweet]

the MVC is basically the same in Play as it is in Rails. [tweet]

the model in Play is rich, not anaemic. [tweet]

testing in play: unit, functional, Selenium, coverage (Cobertura) and fixtures using YAML. Easy for rails users! [tweet]

backgrounding: scheduled jobs, bootstrapping, suspendable reqs using futures [tweet]

interesting modules: CRUD (like Django admin, Rails scaffolds), AppEngine, MongoDB. [tweet]

support for i18n looked good in Play. [tweet]

IDE and editor support for play includes Textmate. [tweet]

play is David Pollak’s second favourite Scala web framework. Hehe. ;-) [tweet]

scala in play was hard: wanted to keep API interop, but also get benefits of the language. [tweet]

benefits of scale for play: 2.8, scalatest, scalate, REPL and Akka integration. [tweet]

@vigosun is demoing building a basic app in Play using scala and eclipse. Play comes set up with H2 like Rails does with sqlite. [tweet]

I spy annotations: my least favourite java language feature. ;-) [tweet]

class Foo extends Model - how it bloody well ought to be. [tweet]

object Foo extends QueryOn[Foo] [tweet]

damn, the Model system in Play looks shockingly simple. [tweet]

the templating language that is begin used with Play looks pretty awesome. [tweet]

not sure about the REST cred of Play: will have to look into accept and so on. [tweet]

“Start using Play! Java now” [tweet]

play is the only java framework that doesn’t induce despair in me. [tweet]

Will I try Play? Yeah. Looks like it might be pretty good. I’d like it if you could use it for non-web projects too! I mean, the simple setup of database stuff, for instance.

Tags: