Typical Programmer

A glittering performance of rare perception


Popular articles
All articles

About me
Hire me

Miasma, a new framework for web applications

28 Jul 2008

This is the first interview posted on Typical Programmer. I plan to do more interviews with programmers who are working on interesting projects and pushing new ideas and technologies.

I had a chance to interview Boyd Hakluyt at O’Reilly’s OSCON 2008 in Portland last week. Boyd is working on a new web application framework called Miasma. Boyd gave a demo at OSCON, and afterward we had some of the local microbrew Portland is famous for and talked about web application frameworks.

Typical Programmer: I hadn’t heard of Miasma until OSCON, and even then I only saw the demo because the room numbers were mixed up on the program.

Boyd Hakluyt: Yeah I got on the program at the last minute. Some of the people who came to the demo were expecting a “birds of a feather” meeting to talk about “life extension for geeks,” which was actually on the OSCON program this year.

You’re flying under the radar with Miasma. When do you expect to have something to release?

I was hoping to have a beta version ready in time for OSCON but we lost a key developer last month so the code isn’t as ready or tested as I would like. I also need to get the web site and documentation finished. The framework was renamed in June so the domain name I had picked out doesn’t work anymore.

What was it called before you renamed it Miasma?

Originally it was called Darlene. One of our lead developers, who wrote the core URL routing code and the template parser named the first version after his girlfriend. When they broke up we talked about renaming it couldn’t settle on a good name that wasn’t taken. When he left the project Darlene didn’t seem to fit anymore. I think Miasma is cool name and no other programming project is using that name. I have a friend working on a logo, too.

How many people are working on Miasma?

Right now it’s just me, but I’m working on it almost every day.

There are lots of web frameworks to choose from. What originally inspired you to write a new framework and what makes it different?

I’ve looked at most of the available frameworks and they all have problems. None of them do exactly what I need to do. I was working on a side project developing an appointment and contact management system for my optometrist and it occurred to me that most of the code I had written could be used to build other web-based applications. My client agreed to let me retain ownership of the code as long as I finished their application for free.

What’s different about Miasma is the philosophy behind it. It’s not just another big collection of classes and objects. From the beginning my plan was to make a framework that the average programmer could use to build the kinds of web sites I work on. You don’t have to be a language geek or understand things like methods or closures. Most of the code you write with Miasma is the HTML and JavaScript you are used to writing.

What language is Miasma written in?

We started with Ruby but ran into too many limitations and performance problems with it. Then we ported the code to Haskell and got it partially working on our laptops, but it was too hard to deploy on our client’s hosting account. One of the most intense ideas we had was a five day long programming contest to write the framework core in as many languages as we could think of. We invited all of our friends who know how to code over, got a bunch of frozen pizzas, snacks, beer, soda, and two XBox 360s hooked up to LCD TVs. We had people writing the framework in Lisp, Scheme, Erlang, C++, Lua, Python, Cat, Forth — everything but COBOL. That was a very cool way to play with different languages.

None of the code from the contest was really beta-quality, though, and we still had problems getting any of it to run on my GoDaddy hosting account, so we decided to go with PHP.

There are so many PHP frameworks already. Why would I use Miasma instead of, say, Zend or Cake?

Cake has a huge manual and is just too big to easily understand. I haven’t used Zend or looked at it but a friend of mine has played with it and told me it’s complicated and doesn’t really hide database SQL or make AJAX easier to do.

My philosophy is to make things simple. If you look at Cake or Ruby on Rails or most of the other frameworks you notice they have hundreds of classes and objects. But a lot of programmers don’t understand object orientated [sic] programming and don’t want to learn it just to make a simple web site. What they want is something that does database operations without forcing them to learn SQL — what the Rails people call CRUD.

With Miasma I’ve concentrated on things that web developers do over and over. When I’m writing a web site most of my time is spent getting variables from the server displayed in the right place in the HTML and debugging JavaScript. It’s not spent making a bunch of classes and objects that will most likely never be reused.

Does Miasma support the Model-View-Controller (MVC) pattern?

Yes. The Wikipedia article about MVC has been a big help figuring out how to organize the code. When you start a new Miasma project you run a script that creates a project folder and three folders inside of that named models, views, and controllers. By starting with that structure programmers are encouraged to follow MVC best practices when deciding which folder to save their scripts in.

A new Miasma project with folder layout showing MVC structure: miasma project layout

Does Miasma use other software patterns?

When people ask about patterns I like to tell them Miasma is based on the simpleton pattern, because it’s very simple to use. I know in real OO programming simpletons are usually a bad idea but I mean it ironically.

Most of the successful frameworks have large developer communities. Ruby on Rails is probably the most obvious example. How will you get that kind of excitement and interest behind Miasma?

I’ve studied how David Heinemeier Hansson [author of Ruby on Rails] has popularized Rails. Many of his talks are available on YouTube. Rails was extracted from a bigger project, and so was Miasma. I plan to start giving talks at conferences like David did when Rails came out. I guess you can think of Miasma as having the benefits of Rails without a lot of hard to understand Ruby OO code, and without the profanity.

Does Miasma have a database abstraction layer? Did you write your own or use an existing database library?

I wrote my own. In the site configuration file, which is XML by the way, there’s a setting for the database you’re using. There are functions for doing database operations like SELECT and INSERT and UPDATE and they choose which PHP database functions to call based on the configuration. The programmer passes arguments that are converted to WHERE conditions and ORDER BY and things like that. It’s much easier than writing SQL. I don’t know SQL very well and that was my incentive for writing the database functions.

An example of Miasma’s database model functions compared to plain PHP. Notice no SQL knowledge required with the Miasma database abstraction functions:

/* plain PHP with MySQL */
$appointments = array();
$apptnum = 0;
$result = mysql_query("
    select * from appontments_table where office=0", $dbconn);
while ($row = mysql_fetch_assoc($result)) {
    if ($row["appt_doctor"] == 1)
    $appointments[$apptnum++] = $row;
}

/* miasma ORM functions */
$appointments = array();
$apptnum = 0;
$wherecond = " where office=0 ";
$temp = mia_model_select("appontments_table", "*", $wherecond);
$appointments = mia_model_filter($temp, "appt_doctor", 1);

You’ll notice there’s no SQL in the Miasma example. One thing I don’t have working yet is making plurals for the table names, like Rails does, so you have to use the actual database table name. I’ll have that working for the beta.

What about templates?

Miasma has a templating engine just like the other frameworks. I looked at probably twenty different template systems but they all had issues that didn’t work for me. Basically you create a template that has placeholders for variables that come from the model or controller. The placeholders are marked in the template by surrounding them with ++var++. When the controller processes the template it reads in the file, uses regular expressions to find all of the placeholders, then replaces those with values from an array of substitutions.

A snippet from a Miasma template:

<div class="appointment">
	<b>Date</b> ++var++DATE++var++ <br>
	<b>Name</b> ++var++FIRST_NAME++var++
        ++var++LAST_NAME++var++ <br>
	...
</div>
<!-- var placeholders can be used in html tags -->
<div class="++var++TYPE_OF_APPT_CLASS++var++">

The template engine is the biggest piece of code and the one that I’ve tweaked the most, because a big template with lots of placeholders can be slow. My goal is to add things like conditionals (++if++) and loops (++for++) so it can do the same kinds of things developers normally do with raw PHP.

I don’t mean to ask a stupid question, but why not just use PHP instead of making a new template language?

The main problems with PHP are no namespaces, and it has way too many library functions that are just too hard to figure out and remember. By giving the developer a smaller and simpler set of library functions they don’t have to worry about all of the junk in PHP. And all of the Miasma functions are prefixed with mia_, so they have a unique namespace, unlike most of the PHP library.

I’m looking forward to a beta release I can try out.

I think a lot of developers are tired of how complicated web applications are, and how huge the frameworks have become. When I see the unreadable mess of JavaScript code on any of Google’s pages, for example, or the contortions programmers go through to get PHP to send a valid SQL query, I know there’s a long way to go with web frameworks. I think Miasma is a pretty big step in the right direction.

Thanks for the beer, and good luck.

Thank you.

Comments

ummmm, 29 July 2008 at 5:48 am

is this article is a joke?

forsooth, 29 July 2008 at 8:22 am

Thanks for the article. I like Boyd Hakluyt’s philosophy. (BTW, his first name is misspelled in the first statement.)

Wolf, 30 July 2008 at 3:06 am

You say “We started with Ruby but ran into too many limitations and performance problems with it.” and choose PHP! What kind of limitations you get with Ruby and haven’t with PHP? I think this article is bullshit.

espressoexcess, 12 August 2008 at 1:35 pm

I have the same problem that Boyd has with overly complicated app frameworks. Who has time to read all that documentation when there’s a client breathing down your neck, and a burgeoning WOW guild to maintain?

I myself have created a web application framework like Miasma, that’s easy for non-programmers to use. Mine’s just called Asma, because it doesn’t have to be my Asma, it can be your Asma too.

Asma does everything with just a single CAsma class, (pronounce it “hhhas-ma” with a Middle Eastern twist). CAsma inherits privately from a Simpleton base class. The class has only one function, doh(), which is really easy to call, as long as you understand that it takes no arguments and returns no result. And the CAsma class is declared final to prevent people from destroying my framework’s simplicity by subclassing.

Lots of successful web sites have been built on the Asma framework (virtual pet rock ecommerce site, my D&D club site, etc.) and I have to say they all work flawlessly.

Or at least the parts of them that use the Asma framework do. I can’t vouch for the quality of all that other HTML, JavaScript and PHP crud that people like to wrap my nice Asma framework with.

Mark, 13 August 2008 at 9:53 am

I know in real OO programming simpletons are usually a bad idea but I mean it ironically.

Do you think maybe he is thinking of singletons, but he forgot what they are called?

I was looking for the April 1st date on this article.