2009/03/06

Let's use real languages for builds

For the last few months, I've ben away from the Ruby land, doing first a Java and now a .NET project. I also had to write a few hundred lines of Python. Hold on with condolences - it wasn't a bad thing at all. I actually loved the opportunity to tinker with other mainstream platforms and see how things are there these days. Besides, JetBrains makes wonderful tools. Besides, next time someone tells me Rails has too much magic, I'll be laughing - compared to Spring/Hibernate? - give me a break! But I digress.

This is to report that recent Java/.NET experience has GREATLY improved my appreciation of the usefulness, maintainability and sheer beauty of a well-written Rake build. A build in a real programing language is AWESOME. It is my [now well-informed] opinion that this is one of the things corporate IT sector should learn in the build/deployment area - replace Ant and MSBuild with tools that use real programming languages for expressing the build logic. I.e., Rake or similar.

Why would you want to do it? Here is an example. On the aforementioned Java project we needed to include a piece of logic into the build that would behave roughly as follows:

* Grab build artefacts for a specified build from Cruise
* Copy them to one or several servers (one for test environments, several for production)
* Unpack some of them on the target box(-es)
* Flip the symlinks
* Gracefully handle a failure of any step
* Be mindful about the fact that the target environment may or may not be a cluster.

This task was handled by a fellow ThoughtWorker, very smart guy with substantial platform experience in the Java land. Since the client asked us to avoid introducing too many alien artifacts, he did it all in Ant. As far as I remember, it took something like two days to sort it all out. The last two bullet points proved particularly hard. Apparently (and what a surprise!), XML is not the best way to describe loops and conditional statements.

Certain parts of the solution were a great laugh (of a bitter/cynical variety). The Daily WTF doesn't have a Hall of Fame, but if it did, this stuff should be featured there. Once again, we are talking about a very smart guy - many programmers could not even find a way to do it, I suspect.

If we were not constrained in the choice of tools, we would go for Rake/Vlad, and be done with it in under two hours, conservatively speaking - been there, done that. Overall, I think that a Rake build for that project (fairly straightforward Java web app), would be four to five times smaller, an equivalent number of times cheaper to create, and noticeably easier to maintain, too, despite being an alien artifact for the support team. Benefits of using Ant (which supposedly makes it easier to compile a bunch of Java classes and make a war file out of them) proved imaginary as soon as we started addressing automated deployment requirements.

Two days extra work is not such a big deal, if it is just an isolated incident - but it wasn't. Couple of days here, a day there - these costs do accumulate. By the way, before anyone asks - yes, we did look into Maven 2. Outcome: it's quite possible to coerce me into using Ant for another Java project, but I would flatly refuse to touch Maven with a ten feet pole - consultant ethics demand it. And yes, I do have logical arguments to support this position with. It just isn't the subject of my post.

If memory serves, it's been 5 or 6 years since the creator of Ant publicly stated that programming in angled brackets was a bad idea. And for at least five years we have some great alternatives to it coming from the dynamic languages community. These things are neither new, nor unproven anymore. They offer very tangible benefits - that's the point. Once you know about these alternatives, the only real reason to continue using Ant (or Nant, or MSBuild) for any build that goes beyond "compile and run unit tests" is inertia. Which, up to some point, is a perfectly good reason - new shiny toys tend to have nasty flipside. But that point for switching from things like Ant to things like Rake is past us, in this pundit's opinion. Question is, when are we, as an industry, finally going to do it?

13 Comments:

At March 6, 2009 at 10:40 AM , Blogger David Carver said...

Don't forget that Linux/Unix has had this ability for years with it's various scripting langauges. I used REXX for builds under OS/2, Windows, etc. Ant works wonders if you add Antcontrib which adds some more programming to it. Rake is just another tool. There are multiple ways to re-invent the same wheel. Use the correct tool for the correct job. I personally think Ruby and it's related items are over hyped, until the next great thing comes along.

 
At March 6, 2009 at 3:45 PM , Blogger Alexey Verkhovsky said...

Ant works wonders for a narrow set of tasks. As soon as you step outside that set, it becomes excruciating pain. And yes, we do use antcontrib - it slightly extends that set. Rake still kicks Ant's ass.

FWIW, this opinion is certainly subjective, but it's not based on hype. I had to deal with non-trivial builds in every technology mentioned in the post, except Maven.

 
At March 7, 2009 at 6:00 AM , Blogger Julian said...

While I agree that programming in XML is wrong, I wonder if the exercise above is asking the tool to do too much.

Ant just isn't good at taking into account different environments, etc. Tools like cargo help you make a developer build that has a simple deploy step. I like to have an ant build that focuses on making artifacts (wars, configurations, db files) that you can deploy. I always put those artifacts onto a filesystem in a kind of repository and then try and use something else for deployment.

If it all possible you should be writing that second script in a dynamic language. Trying to extend Ant using Antcontrib is like putting mag wheels and a whale tail on a VW bug: it still won't be a Porsche.

 
At March 7, 2009 at 11:22 AM , Blogger Alexey Verkhovsky said...

I prefer it the other way around. Have a Rake (Groovy, Scons, what have you) build, use ant *tasks* in it if they save time.

Reason: Ant sucks (compared to Rake) even for such things as expressing task dependencies (especially when they change based on the target environment), for skipping tasks when task outputs are up to date with their sources, etc. It's not impossible to do any of it in Ant, just an order of magnitude harder.

 
At March 7, 2009 at 3:40 PM , Blogger Kris said...

I completely agree with your post. I was on a project once where the ant tasks became non-trivial. Once it got to the point that we were throwing and catching exceptions in ant, we realized that we crossed the line from declarative build configuration to scripting, and it sucked. Hard.

By comparison, rake files are a more succinct way of doing the same simple stuff that ant is good at, but easily transitions into the hard stuff that ant is bad at.

 
At March 9, 2009 at 6:44 AM , OpenID jasonmbaker said...

Making humans edit XML should be a crime against humanity.

I've had good luck using scons for some of my C++ stuff though.

 
At March 9, 2009 at 6:44 AM , Blogger shevegen said...

I think this may be difficult. Java is so verbose that ant chose XML files (yuck).

Ruby is so short and elegant that you can use it.

But what would you do in Java? The Java solution will always be longer.

 
At March 9, 2009 at 7:13 AM , Blogger jonelf said...

You say you would use Rake for building Java. Ever tried Buildr http://buildr.apache.org/ or the now seemingly sleeping http://raven.rubyforge.org/ ?

 
At March 9, 2009 at 9:26 AM , Blogger c15c8ra1n said...

I work for a strictly .NET-on-Windows company, but we still use rake for building. The actual compilation is still done with MSBuild, but we have a lot of other tasks written in ruby, like migrating databases, managing IIS tasks, etc. Rake really worked out great for us.

I don't get why some programmers feel that the tools they use to get the job done everyday must be written in the same language or platform that they program on.

 
At March 9, 2009 at 12:55 PM , Blogger Nick said...

I know you're probably going to get a million suggestions, so I figure I'd throw mine in as well. :) Have you looked at GANT? (http://gant.codehaus.org/) It lets you write ANT build files in Groovy, giving you a real powerful scripting way of doing builds. (Check out its buildfile for some examples of what it can do.)

 
At March 9, 2009 at 7:26 PM , Blogger Alexey Verkhovsky said...

Yes. Although I have never had a reason to look into Gant beyond demos, but it does look like the sort of build technology I'm talking about. Same goes for buildr.

 
At March 9, 2009 at 7:31 PM , Blogger Alexey Verkhovsky said...

Using the same language in various parts of the project, including the build script, has some merit. For one thing, it makes it that much easier for newcomers to pick it up.

The thing about Ant (Nant, MSBuild, Maven) is that it's not Java (or C#), anyway. It's freaking angled brackets! Which is really easy for a computer to parse, but that is the only redeeming feature of XML as a language syntax.

 
At March 10, 2009 at 10:26 AM , Blogger Adam said...

You make some good points.

To be fair to Ant, you can mitigate a lot of the issues you describe by copious use of the <groovy> task. AFAIK Gant is basically a layer of abstraction on top of the Groovy AntBuilder, which this task also provides access to.

I'm project owner of Kundo - https://kundo.dev.java.net - which also uses AntBuilder to squeeze that extra something out of good old Ant.

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home