28th January, 2009

Your framework probably sucks

If you're writing a framework, I recommend you stop. Right now. Go do some sports, read a book, enjoy the world. Come back and then use an existing one, or none at all, just use a programming language.

Frameworks suck. Frameworks suck balls. You may think your framework is the best thing since the dogs tits or whatever but your framework sucks. They are time-wasting, spaghetti-code generating balls of logic wound like a ball of twine, which easily lure you in.

Why I hate frameworks...

Unless your framework was handed on stone tablets down a mountain from god and compiled by Jeebus himself, it will cost you time maintaining it, time using it and time trying to convince people why it's the best thing since last months Best Thing.

Developers mindsets are geared toward solutions. Here is a perfectly rational conversation a developer might have in his head:

Developer: "Hmm, I'll need a quick form for my web app here. I could just output some HTML with some server code to handle the submit... but I'll probably need more forms later, I'll just build a Form Management Framework."

Admit it, you've been there. It may not be forms, it may not be a web app but you've created unneccesary work building a system which will require maintenence. What's worse of all, management will probably encourage it. It is easily justifiable.

Developer: "Well, it took two days to finish but now we have this Form Management Framework which will cut any future development time"

Manager: "That makes sense, we have more work in the pipeline and I now have a new smart-sounding product which our clients will love." (He goes off thinking about how he can sell the Form Management Framework)

What happens now is a vicious feedback loop where fringe requirements are introduced and the complexity of the framework increases at an exponential level. "Who would possibly want to add images into forms?" the developer cries. "It's a new requirement" the manager replies. Image-form-injector-combobulator is added. Settings are obfuscated and badly named. "Is that attribute class the class of the CSS or the server side code?" a new developer asks. Nobody can remember.

Why did this happen? We already had a framework, it's called the Programming Language. It's the best framework of all, because you can do anything you like within the boundaries of the language.

Ever wondered how there are so many Python web frameworks and not so many .Net or Java frameworks? It's because .Net and Java are frameworks not languages. They are amazing frameworks, written by incredibly clever people, but frameworks limit you to the framework boundaries.

With every new client comes a new requirement, and hence a new framework is required. We've tried hauling in every possibility into the framework, they're called .Net and Java - try learning the entire system assembly of either, they are huge.

Going back to the earlier example; the reason all of this happened? The developer felt it beneath him to write the following:

import cgi, os, smtplib

if cgi.FormContent.value("message") != None:
    print(file("form.html), "rt").read())
    from_addr = "webserver@globalconglom.com"
    to_addr = "contactus@globalconglom.com"
    subject = "Contact us form submission"

    email_message = []
    email_message.append("From: " + from_addr)
    email_message.append("To: " + to_addr)
    email_message.append("Subject: " _ subject)

    message = "\n".join(email_message)

    server = smtplib.SMTP(smtp_server)
    server.sendmail(from_addr, to_addr, message)

There. The closer to a language you are, the easier it is to add those pesky fringe cases clients require. Taking the above example, if we needed to add a second address to send it to, we would have to implement that in the framework, instead of being a one line add.

What gives me the right to post derisory comments about frameworks? I've written them. I spend my life writing them. This blog is powered by a CMS built on a Python web framework I wrote. There's probably a Form Manager somewhere in it as well, and I feel I have reached an epiphany moment. Now I know how far I can obfuscate it, I just need to reel it in and do the actual amount of work required.

This was mainly cathartic, aimed at me.

Thanks for reading.


Add Comment

The opinions expressed here are my own and not those of my employer.