JSON article

JSON for the masses is being widely linked lately.  I find it interesting and a bit perplexing.  It purports to show you how to “program in JSON” — which boils down to using Javascript objects as namespaces to hold closely related functions and variables.

It’s a good idea.  Namespaces are helpful and clarify things.  It purports to make things “object-oriented,” which I find a kind of unfortunate claim.  There’s a brand of “object orientation” which basically is nothing but procedural programming which uses classes and/or objects as namespaces — where an object of a given class has no purpose other than as a place to hang a bunch of conceptually related methods.  Or where certain classes are never instantiated at all and just serve as namespaces for their various methods.  You see bits of this even in respectable object oriented languages, e.g. a Math class which exists only to put the sqrt() method.  But it’s kinda lame, as far as object orientedness goes.  And it’s mega-lame if you’re doing it all the time.  (Mega-lame as far as OO goodness is concerned.  Namespaces are still better than no namespaces, though.)

The other thing that seemed odd about this article was that as far as I can tell, what he’s proposing isn’t actually valid JSON.  JSON is supposed to be a data serialization language, like YAML. If you check the spec, you’ll notice function objects are not there.  So what the author is writing about is not strictly speaking even JSON.  And it’s definitely not there to do what JSON is supposed to do — serialize objects for transmission from one place to another.

So it’s a nifty thing, a good idea, but not really very object-oriented at all, and not really JSON at all.

It does kind of show off how easy it is to mold Javascript into an elegant shape though.  Worth reading for that, I think.