The geekery continues!
May. 20th, 2009 08:47 amSo, 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."
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."
no subject
Date: 2009-05-20 05:01 pm (UTC)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... :-(
no subject
Date: 2009-05-20 06:18 pm (UTC)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!
no subject
Date: 2009-05-20 06:27 pm (UTC)Maybe a magazine article out of this?
Date: 2009-05-27 02:54 pm (UTC)