scripting languages

Levi Pearson levipearson at gmail.com
Tue Nov 9 03:29:53 MST 2010


On Tue, Nov 9, 2010 at 1:32 AM, Aaron Toponce <aaron.toponce at gmail.com> wrote:

> Hmm. Using JavaScript as an administrative scripting language... I don't
> know how I feel about that. Knowing that it was designed specifically
> for the web, makes it seem like a hack getting it to perform in fuction
> like Bash, Perl or the others.

Brendan Eich and the supporters of the JavaScript (initially called
LiveScript) at Netscape were big fans of Scheme, which is actually how
they lured Eich in to work on it.  This is why it manages to be a
pretty decent language despite being hampered with the Java-like
syntax and years of terrible implementations in web browsers.
However, there was too much time pressure and orders to look like Java
that made for some less-than-desirable decisions.  See here for a
discussion of some of the stupid:
http://jwz.livejournal.com/1307198.html

However, despite being designed to do browser stuff, the language
itself isn't tied to web-specific things.  This isn't like PHP, where
the designers had no idea what they were doing and just hacked stuff
together until it kind of did what they wanted.  Eich had read SICP,
which should (or a suitable substitute, such as CTM) be required
reading for anyone thinking of designing a programming language these
days.  The intersection of the anonymous function closures (from
Scheme/Lisp) and prototype-based OO features (from Self) pretty much
out him as a programming language nerd.

>> You get the most expressive and powerful OO environment anywhere,
>
> That's a balsy claim, definitely considering some heavyweights like
> Perl, Python and Ruby. How about a comparison of JavaScript to Perl or
> the others? Could lead to an interesting discussion.

Perl 5 OO is stupid and ugly.  Clearly an afterthought.  Of course,
Perl function calls are ugly and stupid too, but their excuse is they
were borrowed from shell and awk and other abominations that we are
sometimes forced to program in.  You can do crazy awesome stuff with
Perl OO, I'm sure, but that's just because Larry Wall is an evil
genius or something.  Anyway, Perl is expressive and powerful and
arguably OO, but I wouldn't call it an expressive and powerful OO
environment.

Python is powerful, but loses points for expressiveness.  You kind of
have to write programs the way Guido thinks you should write programs,
so they always look about the same.  It's all objects, but the
programming interface isn't all OO.  Python has some really stupid
variable scoping issues too, like where assigning to a variable in
nested scope shadows instead of rebinding it.  This is why I prefer
explicit declaration of variables.

Javascript is different from all of the above in that it's
prototype-based, which means that you don't have the usual notions of
object class and inheritance.  Instead you can clone objects, and you
can set a 'prototype' reference on the object that points to an object
to look at for properties that are not defined on the object itself.
As you can see, you have the building blocks necessary to create a
system of class-based inheritance if you want, but you can also create
other things with those blocks as well.  This does give you some extra
avenues for expressing ideas in code, and it's probably what the
quoted person was referring to.

Ruby does classes instead of prototypes, but it's got a lot of other
tricks up its sleeve, including some of the nice stuff it borrowed
from Scheme that Javascript left out, such as call/cc and the
potential for tail call optimization.  It's also got a more flexible
syntax.  I don't know if it's possible to really objectively and
quantitatively compare the OO-expressiveness of Javascript and Ruby,
but of the two I'd probably pick Ruby.

However, once you branch out from the mainstream languages, there are
neat languages like Slate, Io, and their granddaddy Self that all take
the Smalltalk-with-Prototype-OO recipe and take it in various
directions.  And, of course, you could have an altogether different
kind of super-expressive OO language with Factor, or a
super-expressive language that you can easily build an OO system on
like Scheme or Common Lisp.  Really, claiming the most expressive OO
language is kind of silly, since there are a lot of other ways you
might want to structure a program besides objects.

None of this really has any relevance to scripting, though, except to
note that trying to model a unix script as an object-oriented program
could very well be counterproductive, as there's a fairly serious
impedance mismatch.  Unix is (traditionally, anyway) all about
processes communicating via streams of text, while most OO languages
are about program parts accessing one another via discrete messages;
i.e. function calls with fancy inheritable namespaces and some
polymorphism.

        --Levi


More information about the PLUG mailing list