On 2002-10-14 at 20:49:52, Michael G Schwern wrote:
> > It is also, as an example, the behavior required by the ECMAScript
> > specification.
> 
> Heh.  "Because Javascript does it" is supposed to be an argument for? ;)
Heh, indeed.  :) But seriously, you could do worse.  JavaScript receives
a lot of (IMHO) undeserved criticism.  The name is a blatant marketing
ploy, and abuses abound in web pages, but there's really not much wrong
with the core language, and there are even a couple things I wouldn't
mind seeing Perl6 borrow from it.

I'm going to continue my train of thought as it wanders directly off
the rails of Perl6, so feel free to stop reading this now. :)

JavaScript is a fine object-oriented scripting language with
prototype-based inheritance.  (I think that term is a misnomer, btw -
if you create an object using a prototype, then change the prototype,
that later change is visible through the earlier-created object.
That doesn't sound like the behavior of what we normally mean by
the word "prototype" in English.  But it's the standard term.)
Since it is prototype-based, the syntax for defining (or faking)
classes, and subclasses thereof, is a little clunky; and it has no
data hiding - everything is effectively a public associative array,
But both of those things could be said about Perl5, as well, although
Perl5's syntax is less clunky.

On the single axis of O-O purity - which I am by no means advocating as
a general measure of language utility - JavaScript ranks somewhere above
Python (which is itself above Perl5) and below Ruby.  

It has the usual stuff - inheritance (albeit prototype-based);
automatic type coercion among strings and numbers and Objects; regular
expressions (syntax stolen from Perl5, of course); dynamic arrays
(with a variety of manipulation methods that were also stolen from
Perl5: splice, slice, shift, unshift, push, pop); and associative
arrays (every object is one, really).  It also has some a couple
nice features regarding functions:

        They have prototypes, but they're not enforced by the
        language.  A function definition may specify a set of named
        parameters, but any function may be called with fewer (in
        which case the unspecified ones have the undefined value),
        or more (which may be accessed via an array analogous to @_).

        An anonymous function/closure may call itself recursively
        despite not having a name by which to do so.  This in particular
        is something I would like to see in Perl6.

There are some oddly confusing things.  We were talking about what
to return for "failure" in the context of 1/0.  Well, as I said,
JavaScript actually returns +Inf for 1/0, but for other cases it
has *three* different nil values:

        1. undefined (like Perl undef; true of variables that have
                      been declared but not yet assigned any
                      other value)
        2. null (for use when an Object reference is expected)
        3. NaN  (for use when a number is expected)

Additionally, an attempt to access a variable that hasn't even been
declared yet throws an exception, so that could be considered a fourth
case, although it pertains to variables rather than their values.

The biggest problem with JavaScript is the fact that the environment
in which it runs - the interface to the outside world - is not defined
by the language spec.  You can't even write "Hello, world!"
without specifying more information.  (Running in a web browser?
Use document.write().  Running under the Windows Script Host?
Use WScript.stdOut.writeLine().  Running under the Mozilla project's
rhino interpreter?  Use print().)  

Anyway, I don't think JavaScript is going to make any inroads in the
sysadmin scripting language "market".  For Windows administrators, it has
some advantages: it's already there on modern versions of the OS, and
it's a huge improvement over the previous scripting language for which
that was true, namely DOS batch files.   But Windows administrators who
were brought up in the Windows world will probably use VBScript instead of
JScript to access the WSH, and those who were brought up in the UNIX
world will just download ActiveState Perl. :)

Anyway, I'll shut up now.  Just don't knock it 'til you've really tried it. 
:)

-- 
Mark REED                    | CNN Internet Technology
1 CNN Center Rm SW0831G      | [EMAIL PROTECTED]
Atlanta, GA 30348      USA   | +1 404 827 4754 

Reply via email to