I rather enjoyed Mochikit

At my one client we use the Ext javascript library, which is somewhat of an all-singing-all-dancing javascript library with dozens of compound widgets, particularly these huge, heavily abstracted searchable, sortable, selectable grid widgets.  Ext doesn't float my boat.  I wouldn't pick it up to use it on a personal project.  The API just seems so large that I feel I have to look up every call and method.  The fact that it seems to take half a minute to load all the grids and widgets you get on a heavily-ext-ified page doesn't thrill me either.

Tonight I got a chance to sit down and use Mochikit with TurboGears (and Kid).  I implemented a simple live-search page (that is, search a database for the intersection of values which match a set of per-field search values) in about 150 lines of html, javascript and Python.  No big deal, but what made me enjoy it (to the point that I've now spent far more (almost 4 hours now) than the original 15 minutes I'd planned for the spike test) was that it seemed so logical and small, just a small collection of very sharp tools you can use to make Javascript feel more Pythonic.

I like the deferred model (a-la Twisted), and it's there.  I like the signal-slot mechanism (a-la Qt or Pydispatcher), and it's there.  I like functional programming (a-la map, and friends) and it's there.  Even the programmattic creation of html is pretty sweet (nevow's stan inspired).  Basically the code looks just about how I would expect the code to look, short, concise, but readable and easily maintained.

After half an hour with the library I was writing most of my code without reference to the documentation.  About the only thing that really tripped me up was that the signal-based code for onload needs to be bound to the *window* in order to work... rookie mistake I suppose.  That small-enough-to-fit-in-your-mind and regular-enough-to-predict-what-will-be pattern is IMO extremely Pythonic.

One last thought.  Am I the only one who finds that kid/genshi is best exploited by passing model objects directly to the view?  I know, I know, the controller should resolve everything to low-level values before invoking the view... but it's *so* nice to be able to use SQLAlchemy/Elixir bindings to traverse the objects and use common function definitions to provide a consistent view of the objects wherever they show up...  being able to say "conference.owner.company.name" to display the value is just so convenient... even if it does wind up embedding code in the view.

Comments

  1. Kevin Dangoor

    Kevin Dangoor on 10/07/2008 12:04 p.m. #

    Personally, I agree that exposing model objects directly to the view is quite nice. Things get rather tedious, for not a whole lot of gain that I can see, otherwise.

    MochiKit is indeed a nice library (I've written 80 pages in a book about it :).

    At this point, I'd strongly recommend a look at Dojo. (ObDisclaimer: I work with some of the core Dojo guys, but I've taken a good look at the field and wouldn't change my recommendation even if that weren't the case)

    If you start with Dojo's base, you get a library that's like MochiKit (deferreds, signals/slots, visual effects, fast DOM node querying, doesn't have MochiKit's DOM builder stuff though). What's great about Dojo is you can work with that as a starting point and then drag in any additional code you require as you need it.

    Want something like Ext? Just start pulling in components from dijit.*. Need to do Comet? dojox.cometd. Charts? dojox.charting. How about client side templating? dojox.dtl

    There's tons of great stuff in there and a build tool that will pack it all together and shrink it down for fast delivery to the browser.

    It's a far more active project than MochiKit and has a lot in common with MochiKit (and not by random chance).

  2. Kumar McMillan

    Kumar McMillan on 10/07/2008 3:52 p.m. #

    I've worked extensively in both Ext and Dojo and MochiKit. MochiKit is more of a low level tool and doesn't do large scale javascripty GUI building like Ext. As Kevin says, dijit.* is Dojo's version of GUI tools. I have to say I like Ext a little better though and I think it's a bit more consistent than Dojo and I have an easier time finding what I am looking for in the Ext docs.

    But you are right, Ext is monolithic. If you don't want to build a huge GUI cms like thing you probably should just use mochikit or jquery. I too was concerned with the speed of Ext but try it out in Firefox 3 (if you haven't already). It feels 10x faster than Firefox 2.

    I will continue to use Dojo on personal projects because their license is much less restrictive. I am also excited about Dojo 1.2

  3. Kevin Dangoor

    Kevin Dangoor on 10/07/2008 5:37 p.m. #

    My default browser is WebKit nightly at this point, and let me tell you: *everything* is fast. It's great.

    Unfortunately, for most websites, IE is still the lowest common denominator... if something is slow in IE, it's slow for most of your users.

    That is one thing to be said about Adobe AIR apps: you always get to use WebKit with AIR :)

  4. Mike Fletcher

    Mike Fletcher on 10/10/2008 3:48 p.m. #

    Wow, the lazyweb rocks! Thanks for all the information guys, I've begun checking out Dojo and may wind up playing with it on some project in the future.

Comments are closed.

Pingbacks

Pingbacks are closed.