Saturday, March 24, 2007

Web Forms With Erlang

I started a project that I eluded to in my previous entry. I only wrote the specification and started on some code. so it is far from complete. This is what I wrote so far as a "goal" statement:

A mini-framework on top of ErlyWeb to:

1. Generalize a common set of patterns when related to web form development.
2. Siimplify the creation of forms for instant gratification.

This is accomplished by:

1. A general web form behaviour in Erlang, which handles generating new and edit forms as well as deleting and retrieving data for results or details.

2. A specific way of creating multiple amount of forms in a unit.

3. A way to quickly generate forms, which can be played with immediately.

4. An HTML form generator that takes form specificiations an can genereate simple forms as something to start off with before a better design is created.

5. The allowance of the system to easily adapt to new HTML designs and code.

The idea is this: I got a form of something - be it data to fill in from one or more database tables, or email to send, or whatever. The implementation makes a common set of assumptions about what is going to happen to the data.

The assumptions are this:

- This something will be created.
- This something will be edited.
- This something will be deleted.
- This something will be retrieved.

What is being modeled is the common expectations of what will be performed:

- Data needs to be validated
- If validations succeed, we need to know what to do next.
- If the validations fail, we need to know what to do next.

The system will have a sensible set of defaults, making it possible to make a form quickly, with the validations, and the form can immediately be tested (without any database code or what not.) When the form is shown to work, the details can be plugged in. (One idea that came to my head was to have the framework make a temporary table in Mnesia, so the retrieving aspect can be quickly tested.)

My idea is to utilize an Erlang behaviour in this case. With a behaviour, the compiler can check if my specific forms are missing functions, and warn the developer of the missing function.

The result is a framework the mixes a bit of simplicity (sort of what you get with ErlyWeb or Rails instant CRUD generators) as well as being general enough to be actually useful outside of just simple CRUD.

In this process, I have started to rewrite my HTML form builder I mentioned in a prior post. There is a lack of generality in it that I need to fix.

Saturday, March 03, 2007

An HTML Form Builder

Here is a form builder I wrote in Erlang. I had an idea earlier, related to a project that my brother wants me to work on. I thought that it would be fruitful for us to both sit down for a few hours constructing a web site. He does not know how to code, but he can discuss aspects of what I am hacking up, so we can discuss changes while I am coding. I told him that I want to make the process of creating forms quickly, so, in a stroke of inspiration, I threw this little module together.

There is little error checking involved in the code, but then, maybe, given the Erlang guidelines, this is a good thing. Look and see. Maybe you'll find it useful. I am going to update it when I need to.

The code is here. An example form: here. Sample test code: here.

UPDATE: This little sample code makes me extremely happy, because I was able to have a very vague idea of what I wanted, and I was able to translate those ideas into working code in a reasonable amount of time. I think I can attribute this to functional programming and pattern matching. My next step (er, tomorrow :) ) Is to make a web page to generate forms, with interest in accomplishing what I want to do when my brother and I sit down and get some code working for our app.

An Erlang Project

I figured that I am maintaining a focus on a particular language and am going to progress in a particular project for my computer science degree, I might as well use this space to discuss Erlang more and what I am doing in it.

What I am focusing on, for my final-year project is a study of the use of Erlang in the context of web applications. I am evaluating what interesting things that are in Erlang that can be utilized in the context of web programming. For example, is the language robust enough for general web programming? Or, where can we benefit, either directly or indirectly from Erlang's concurrency model?

I am writing two small applications for this. The first is a semi-re-implementation of the Java Pet Store example. The second is a simple instant message server. Both intend to demonstrate the use, for example, of higher-order programming in the context of a real example. In the second example, I hope to demonstrate the usefulness of Erlang as a very good concurrent language with its efficient process model. Can Erlang demonstrate the idea that we can write things like instant message servers (particularly for the web) without the mental overhead of dealing with the problems around multi-threading? I admit that I am not good in multi-threading, but from what I coded up so far, I am so excited of what possibilities that can be done with Erlang.

I will, for sure, be utilizing ErlyWeb, and plan to write a couple of big tutorials when I am finished with my applications (along with the academic paper I will write.)

I am going to post something up here occasionally of whatever activity that is happening in my little world; hopefully people will be interested. (hehehehe)

... also, check out Joe Armstrong's new Prgamatic Programmer book, Programming Erlang: