elfs: (Default)
[personal profile] elfs
So, I've put up my latest geek piece: Fixing an omission from Django's simplejson: iterators, generators, functors and closures, which is exactly what it says it is. Django's "simplejson", which bundles up server-side structures and exports them to the browser for interpretation and display in fat client applications, is okay, but it fails in some common ways.

For example, if I want to render a tree of data stored in a database as a JSON object, first on the server side I have to devolve the database into a massive dictionaries-of-dictionaries or lists-of-lists, and then pass the product to simplejson. The process of devolution usually involves recursing down the tree structure, and the process of rendering involves recursing down the dictionaries-of-dictionaries structure.

Why not write a class or closure that describes the process, and pass that to the JSON renderer, which will build the JSON object with a single recursive pass? A completely great idea as it eliminates this obscure, error-prone, and wasteful interim dictionaries-of-dictionaries, and it describes the rendering process in clear, tight code.

Except, the JSON handler in Django has no idea how to handle a class or closure designed to do that. It does not understand the next recursive or iterative step when presented with one of those as it recurses. My post addresses this issue.

I confess that this was a sidelight on yesterday's research: figuring out how to create a list-of-lists data object in Dojo. That stymied me, and this is a better implementation. Still, I regret not being able to publish a class called "LOLTrees."

Date: 2009-05-20 05:01 pm (UTC)
From: [identity profile] sandhawke.livejournal.com
Random question: why Django?

I haven't settled on a python web platform. I see claims like "You really should have tried Pylons (http://pylonshq.com/) instead of Django. Yeah, Django has all the press; it was invented by journalists. Pylons is still better."

It's hard to know how to evaluate claims like that without first becoming an expert in all the systems... :-(

Date: 2009-05-20 06:18 pm (UTC)
From: [identity profile] elfs.livejournal.com
Well, you kinda have to do just that. I evaluated Pylons briefly because it actually has a Webware compatibility layer; I'd be able to leverage most of my knowledge before diving right in. But ultimately, I decided that press and paradigm favored Django over the alternatives. For one thing, it installed on Gentoo without dragging in a huge number of outside classes, which Pylons did. (That said, Django is much more useful after dropping in several plug-ins, like treebeard, tagging, registration, and so forth; but those are plug-ins above the architecture; Pylons needed a ton of things just for its architecture.)

But underneath it all, Django is just more Python. If, with Django, you want to use SQLAlchemy instead of DjangoDB, you can! (http://lethain.com/entry/2008/jul/23/replacing-django-s-orm-with-sqlalchemy/). If you want to use Cheetah instead of DjangoTemplates, you can! (http://www.eflorenzano.com/blog/post/cheetah-and-django/) Nothing stops you except your own knowledge of Python's inner mysteries.

A second answer is that it's not just Django. I'm just trying to build out an online portfolio, something I never needed when I thought my job was secure. So, after I finish the current Big Project, an application suite for fiction readers and writers (which is a Django/Dojo/MySQL project), I'm going to develop a smaller app (a simple ToDo mananger, leveraging what I learned about Tree and Forest management in the big project) in Pylons, and then something esoteric in SOPE (http://sope.opengroupware.org/en/) or CPPServer (http://www.total-knowledge.com/progs/cppserv/) just for fun. Never know; I might get all crazy and write something in C#/ASP, Gambas, or Java Server Pages.

Or I might take some time to blow the rust off my C chops.

Hopefully, before that happens, I'll have found work!

Date: 2009-05-20 06:27 pm (UTC)
From: [identity profile] elfs.livejournal.com
Oh, and one other point: the post on ElfSternberg.com (http://www.elfsternberg.com/2009/05/20/fixing-an-omission-from-djangos-simplejson-iterators-generators-functors-and-closures/) is not just about Django. Any Python application server has this problem: most of them use simplejson, and simplejson doesn't understand closures or generators. The snippet of code, ExtSimpleJson, works with any application server. We used it at Isilon for the Webware-based UI product, and it will work with aquarium, cherrypy, turbogears, quixote, or webpy just as well.

Maybe a magazine article out of this?

Date: 2009-05-27 02:54 pm (UTC)
From: (Anonymous)
You might consider making a magazine article out of this - perhaps for Dr. Dobbs Journal or another similarly technical venue. Might be good for a little bit of income.

Profile

elfs: (Default)
Elf Sternberg

December 2025

S M T W T F S
 12345 6
78910111213
14151617181920
21222324252627
28293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 1st, 2026 08:35 am
Powered by Dreamwidth Studios