One Thing About Lisp That Is Better Than Other Languages

March 18, 2008

Ruby:

>> 850/550
=> 1

Python:

>>> 850/550
1

JavaScript:

>>> 850/550
1.5454545454545454

Perl:

perl -e 'print 850/550'
1.54545454545455p

Lisp:

[1]> (/ 850 550)
17/11

Posted in Technology | Tags Javascript, Python, Ruby, Perl, Ratios, Fractions, Lisp | 0 Comments

The Web Application Framework Candidates

February 14, 2008

The web application framework race is heating up, so let's take a moment to meet some of the candidates.

Java

George W. Bush

The current leader in the web application framework space, has a declining approval rating from the general public, but still maintains support from members of the static typing party.

Rails

Hillary Clinton

One of the leading candidates from the dynamic typing party. This candidate has experience that proves she can bring change.

Merb

Barack Obama

A candidate from the dynamic party who is quickly gaining support, running on his campaign of hope. Has a stance similar to that of Rails on many of the campaign issues.

Django

John Edwards

Another strong dynamic party candidate, but having a hard time stealing the spotlight from the two dynamic party candidates, despite running on a strong platform.

Grails

John McCain

The leading candidate for the static typing party, particularly among moderate static typers, but having a hard time gaining support from conservative members of the static party who claim that he is too dynamic on some issues.

Scala

Ron Paul

A candidate that appeals to some members of both the dynamic and static typing parties, quickly gaining notoriety on the web for his support of once unconventional ideas like functional programming.

Posted in Technology | Tags Django, Merb, Scala, Python, Ruby, Java, Rails | 4 Comments

Evolutions - Migrations for Model-Centric Apps

November 24, 2007

There is a project for Django called Evolution, which is conceptually similar to Rails' Migrations. There are some differences between Evolutions and Migrations, mainly due to the fact that Django is model-centric, meaning that you define the attributes of your models in the code and generate the database from that. Rails, or I guess ActiveRecord more specifically, as you probably know, is the opposite, where you define your database tables and an object model is generated at runtime from the database metadata. So I guess you would call that a database-centric ORM. Here's their take on the differences:

Isn't this just ActiveRecord::Migration in Python?

Superficially, yes, but not really.

There is a degree of similarity - the Django Evolution syntax is
a DSL for describing the changes that have been made to a model.

However, there are also some significant differences. In addition to
ActiveRecord::Migration, Django Evolution provides:

    1. An audit trail - a permanent archive in the database of the
       changes that have been applied, and when.
    2. An automated hinting scheme. If you don't want to write the
       migrations yourself, you don't have to.
    3. Validation that an evolution script will leave the database
       in a state consistent with the current model definition.

These differences are largely afforded by the model-centric design of
Django itself. Whereas a Ruby on Rails model is a description of a
database that has been created by hand, Django uses the Python model
to creates the database. As a result, the model definition is canonical
- not the database.

This means that audit, hinting, and verification schemes can use the
Django model as a point of reference. A Django Evolution script is
much more than just an alternate syntax for SQL ALTER statements - it
is an evolution scheme that is bound to the canonical model definition.

The DataMapper project is a model-centric ORM for Ruby apps and as that project continues to grow, their could be some ideas borrowed from Django Evolution, although they do already have their own thing going on with Auto-Migration.

But I'm a Ruby guy, so I've got to take one shot at them here :). They say "the Django Evolution syntax is a DSL". Really?

MUTATIONS = [
     AddField('Author', 'location', models.CharField, max_length=100, null=True)
]

I'm sorry, but if that's a DSL, then what isn't a DSL? In my opinion, there is too much Python syntax to call that a DSL. It's a subtle difference but this is a DSL:

add_column :authors, :location, :limit => 100

The question when is it a language specific library and when it is a DSL? Would you call this a DSL?

Mutation m = new AddField("Author", "location", CharField.class);
m.setMaxLength(100);
m.setAllowNulls(false);
Mutations.add(m);

Posted in Technology | Tags Django, Python, Ruby, Rails, DataMapper | 0 Comments

Is your language beautiful?

July 9, 2007

There is a good presentation posted over on infoq.com by Glenn Vanderburg called The Beauty of Ruby. First of all, I like the format of the presentation on that site. You get the video of the speaker, but you can still see the slides below it.

I agree with all of his points about Ruby, which are all reasons why I've been doing all of my programming lately in Ruby. There's a point he makes early on in the presentation that I think is probably very accurate. Most people who really give Ruby a try on a real project with an open mind will find that they love it. The key is that you must unlearn what you have learned. Some things that would be considered a bad idea in other languages turn out to be not a problem in Ruby, for one reason or another.

In this presentation, Glenn is careful to focus more on what he likes about Ruby, and less what he doesn't like about other languages. But as is inevitable when discussing a language, there are comparisons to other languages. Perl gets the most criticisms, and Java some as well, but very little criticism of Python. Lisp and Smalltalk, as usual, get some love but some criticisms as well. So I'm wondering, is your language beautiful? What parts of your language do you consider to be beautiful, specifically when compared to Ruby?

Posted in Technology | Tags Python, Ruby, Perl | 0 Comments

Typo problems, new site coming soon (hopefully)

December 13, 2006

This site is currently using Typo, which is blog software written using Ruby on Rails(RoR). It uses Mongrel to run RoR. Apache is the actual web server, it passes requests intended for RoR to mongrel, which then serves the request.

I originally started this site with WordPress, which is PHP-based blog software. I'm not a big fan of developing with PHP, and I was hoping to start doing some custom things with my site, so I switched to Typo, so that my site would be running RoR, and I could make my own extensions using RoR.

Since then, I've discovered a few major design flaws with RoR, so I'm not writing any code in RoR now. First of all, and this isn't really a design flaw, but more of a bug, is that some combination of Typo, Mongrel and Rails is causing a serious memory leak. Typo has caused my entire VPS instance hosted at VPSLand to become unreachable. This has caused this site to be down over the past few days. I've never had that kind of problem with a Java app.

Aside form the memory leak issues, and general difficult of setting up a stable rails site, the biggest thing I don't like about RoR is that your application model is inferred from the database at runtime. I'd much prefer it the other way around, where I write a domain model in code, and then the framework generates the database for me.

The reason why it isn't like this in RoR is because Ruby isn't a statically typed language. There has been a lot of hype around dynamically typed languages, but I think they have disadvantages as well. Since I can't create a class in Ruby and declare what type each property is, there is no way to automatically generate a database based on the model.

This is what got me interested in Django. Django is another web framework, but based on Python instead of Ruby. Python and Ruby are both dynamically typed languages, similar in a lot of ways, but they also have their differences. With the Django project, they chose to create pseudo-typing within Python, where you define the type of property of an object in a way that the framework understands it, but not the Python language itself.

I like Python and Django, but I always thought to myself, wouldn't it be nice if the language was optionally typed, to that you could declare the type if you want to, so that the type could be used as metadata by a framework?

I do most of my programming in Java, so I came to the realization that there are great things about Python, Django, Ruby and Rails, but Java, Stripes, Hibernate and friends have advantages too. I decided that although Python/Django and RoR (less so RoR, in my opinion) certainly seem like great ways to build web apps, I don't think there's an order of magnitude increase in productivity over Java, as some have claimed.

But when turning back to Java, one thing I realized I missed was the true object oriented-ness that dynamic langauges allow. For example, in dynamic languages, to store a user object in the database, you use user.save, whereas in Java, you do something like userDao.save(user). Also, the succinctness of the dynamic languages are great, whereas Java verbosity can be almost ridiculous at times. Try this one on for size:

private static final List<Map<String, Date>> DAYS =
    new ArrayList<Map<String,Date>>();
static {
    try {
        Map<String,Date> map = new HashMap<String,Date>();
        map.put("Pearl Harbor",
            new SimpleDateFormat("MM/dd/yyyy").parse("12/07/1941"));
        DAYS.add(map);
        map = new HashMap<String,Date>();
        map.put("Iwo Jima",
            new SimpleDateFormat("MM/dd/yyyy").parse("02/19/1945"));
        DAYS.add(map);
    } catch(ParseException ex) {
        ex.printStackTrace();
    }
}

public static void main(String[] args) {
    for(Map<String,Date> day: DAYS) {
        for(Map.Entry<String,Date> e: day.entrySet()) {
            System.out.println(e.getKey()+", "+e.getValue());
        }
    }
}

And then in a yet-to-be-discussed dynamic language:

def days = [ 
  'Pearl Harbor' : new java.util.Date('12/7/1941'),
  'Iwo Jima' : new java.util.Date('2/19/1945')
]
days.each { key, value -> println "$key, $value" }

So, wouldn't it be nice if there was a dynamic, optionally typed language that would allow us to build a really great, object-oriented web application framework with a syntax as succinct as the syntax of fully dynamically typed languages? Well, there is, and it is Grails.

Grails is a web-framework based on Groovy. Groovy is a scripting language that runs in the Java VM. It complies to Java bytecode. This is nice because you can build web apps using Groovy on Grails (GoG?), and then deploy to a regular Java application server, such as my personal favorite, Resin.

The other nice thing about Grails is that it leverages all the existing Java frameworks, such as Spring and Hibernate. It puts a nice domain specific language on top of hibernate to make using Hibernate even easier.

I'm just getting my feet wet learning Grails, and the best move I've made so far is to purchase the e-book version of The Definitive Guide to Grails. I've found the documentation on the grails site to be ok, but the book is great. It's a must read for anyone looking into Grails. My only criticism of the book so far is that they may have published it a little to early, because for example if states that Grails doesn't support many-to-many relationships, when in fact it does as of version 0.3.

So the point of this long technical discussion is that from what I've read about Grails so far, it looks interesting. I'm going to try to get a new version of this site developed with Grails, and I'll try to make posts here of my progress, assuming Typo doesn't bring down my site again.

Posted in Technology | Tags Django, Python, Ruby, Grails, Java, Rails | 2 Comments

<< Newer Articles   Older Articles >>