Thursday, August 6, 2009

JavaScript

First, All the News that Fits

NY Times, yesterday: Google’s Android Jumps to the Living Room

Earlier this summer: Microsoft Wants Gadgets to Run Windows

JavaScript

You have people writing JavaScript right now. You did not choose this language. You did not invent the Internet. (Al Gore did, remember?) Brendan Eich, then at Netscape, invented this small scripting language for the then-dominant Netscape browser. If you want to run code within your visitor's browser (something as simple as rotating product pictures) you can do this in any language you choose, provided you choose JavaScript.

Yesterday I was writing JavaScript. SketchUp Rubies, written in Ruby, run their user interface in browser windows. Half or more of a Ruby may be JavaScript, not Ruby.

Actually, I don't write JavaScript. I write the subset that Doug Crockford (Yahoo's JavaScript guru) identifies in his book JavaScript: the Good Parts. JavaScript has other parts, but you can ignore them without losing any functionality. Stick to the good parts. Here's one:

python = {species:'python sebae', diet:'vegetarian'};

python.name = 'Monty';



I just created an object named "python". It had two characteristics (data members, if you prefer), "species" and "diet". (No, python sebae is not a vegetarian species. This is my pet python. I don't want him to eat the kitten.) After creating the object, I gave it another attribute, "name". No, there is no class from which this object was instantiated. As yet, python has no methods.

More exactly, python is an Object. Object is the superclass of all objects. As a practical matter, this is important if you are creating a JavaScript interpreter. You can ignore it if you are writing JavaScript.

This simple syntax (I'd call it pythonic!) is the basis for JSON, JavaScript Object Notation. JSON, invented by Doug Crockford, is a simpler alternative to XML for storing and retrieving objects. (For security reasons JavaScript cannot do disk I/O except for cookies. JavaScript plus X is needed for generalized disk I/O. For SketchUp Rubies, X is Ruby and the SketchUp API.)

Where JavaScript gets most pythonic is in its functional programming, which is a thing of beauty. I'll see what I can come up with for that topic tomorrow.

No comments:

Post a Comment