SpiderMonkey / OSSP js?

(7rans) #1

Anyone here use SpiderMonkey / OSSP js? I wondering how that works out
as a standard (not strictly web oriented) programming language and how
it compares to using Ruby in that regard.

  http://www.ossp.org/pkg/lib/js/

Thanks,
T.

(James Britt) #2

Trans wrote:

Anyone here use SpiderMonkey / OSSP js? I wondering how that works out
as a standard (not strictly web oriented) programming language and how
it compares to using Ruby in that regard.

  http://www.ossp.org/pkg/lib/js/

Interesting.

I've not used it, but I suspect that Ruby offers greater expressive power, and that anything SpiderMonkey has that is not part of Ruby would be (relatively) easy to add.

For example, there's been threads here on prototype-based programming (someone wrote a lib for it, too, I believe), and a recent (well, May 2006) article on Ruby Code & Style by Topher Cyll discussed assorted functional niceties one can add to Ruby.

[0] http://www.artima.com/rubycs/articles/patterns_sexp_dsls.html

Still, I'd be curious to hear SpiderMonkey stories.

···

--
James Britt

"Hackers will be expelled"
  - The Breakfast Club (1985)

(grrr) #3

Whats there to wonder? Its javascript (=ECMAscript), standalone (instead
of browser based interpreter).

Its a simple c-syntax like scripting language with pseudo OO like
features thats IMHO painful, limited and clunky to use and I dont see why
would anyone want to use it for programming anything but web client apps
when alternatives like Ruby exist. Hell programming in java would be more
fun and productive!

The fact that on the project page the developers write things like
"JavaScript is a great programming language" makes me dubious of their
judgement - IMHO JS is mediocre scripting language -must be written by
some young whippersnapper cs-student.

To get the full monty on JS google up 'ecmascript reference'.

GRR

···

On Sun, 20 Aug 2006 13:19:24 -0700, Trans wrote:

Anyone here use SpiderMonkey / OSSP js? I wondering how that works out as
a standard (not strictly web oriented) programming language and how it
compares to using Ruby in that regard.

(Gavin Kistner) #4

Trans wrote:

Anyone here use SpiderMonkey / OSSP js? I wondering how that works out
as a standard (not strictly web oriented) programming language and how
it compares to using Ruby in that regard.

My company uses SpiderMonkey as the JS engine for the scripting
component of our 3D playback engine for the PC (and also Lua in another
branch of product). It's quite nice to be able to have JS objects that
map onto C++ objects, so that the methods you call are executed
full-speed.

For example, within our 3D world, we have vectors and 4x4
transformation matrices. Within JavaScript, you can do something like:

function onUpdate( )
{
   this.someVector.transform( parent.lastGlobalTransform )
   parent.rotation.lookAt( this.someVector )
}

And you get blazing fast matrix transforms, rotation adjustments, and
so on.

How does it compare to Ruby? In what sense? It's faster, for sure. As a
language, it's not nearly so nice as Ruby.. Although you can make
methods behave like properties using the __defineGetter__ and
__defineSetter__ methods, these are last on the lookup chain and
dreadfully slow to use.

Did you have specific areas you're wondering about a comparison?

(James Britt) #5

grrr wrote:

Anyone here use SpiderMonkey / OSSP js? I wondering how that works out as
a standard (not strictly web oriented) programming language and how it
compares to using Ruby in that regard.

Whats there to wonder? Its javascript (=ECMAscript), standalone (instead
of browser based interpreter).

Its a simple c-syntax like scripting language with pseudo OO like
features thats IMHO painful, limited and clunky to use and I dont see why
would anyone want to use it for programming anything but web client apps
when alternatives like Ruby exist. Hell programming in java would be more
fun and productive!

If you think of JavaScript as an OO language (or a class-oriented OO language) you may find it awkward and disappointing. It is more like Lisp or Scheme or Self. Or Ruby.

http://www.crockford.com/javascript/little.html
http://w3future.com/html/stories/hop.xml
http://www-128.ibm.com/developerworks/library/wa-javascript.html

JavaScript has gotten a bad rap, largely because almost all the examples are crap and try to use the language as a script version of C or Java. (Quick way to judge a JavaScript book: look in the index and see how many pages are devoted to prototype. (And if you think I'm referring to a particular AJAX library, then you've been reading the wrong material.))

I prefer Ruby to JavaScript, but programming in JavaScript is still fun, certainly much more fun than coding in Java.

As an alternative language that offers interesting ideas, consider using Io.

http://www.iolanguage.com

···

On Sun, 20 Aug 2006 13:19:24 -0700, Trans wrote:

--
James Britt

"Programs must be written for people to read, and only incidentally
  for machines to execute."
   - H. Abelson and G. Sussman
   (in "The Structure and Interpretation of Computer Programs)

(David Vallner) #6

grrr wrote:

Its a simple c-syntax like scripting language with pseudo OO like
features thats IMHO painful, limited and clunky to use and I dont see why
would anyone want to use it for programming anything but web client apps
when alternatives like Ruby exist. Hell programming in java would be more
fun and productive!

-1, Troll (and gods what a blatant one)

Prototype-based OO *is* OO, even if you don't understand it. (I'll admit at this point I prefer the Self / IO style of prototype-based OO than Javascript's, but that's personal preference.)

If you counted language feature for language feature, JS and Ruby would probably end up evenly matched. (Although JS lambdas have some gotcha I can't recall now. Something about only being copying closures or some such.) I even believe the Prototype library implemented some form of mixins, as well as a class-based object system. Interestingly, it seems simpler and more straightforward to implement a class-based object system in a prototype-based environment than the other way around.

Yes, the standard library is very basic. But it's not that small given JS is a language that was designed to be lightweight and embedded in other applications, definitely when compared to other languages in that field, like Lua or the aforementioned IO. And you really don't want to compare the quality of documentation in that field - developer.mozilla.org would very clearly win in completeness and consistency.

I've always viewed JS as a "sucks less than you think" language. The lack of an import mechanism is perhaps the most annoying, but I have been known to write relatively clean and modular JS code nonetheless.

David Vallner

(Gavin Kistner) #7

Phrogz wrote:

My company uses SpiderMonkey as the JS engine for the scripting
component of our 3D playback engine for the PC (and also Lua in another
branch of product). It's quite nice to be able to have JS objects that
map onto C++ objects, so that the methods you call are executed
full-speed.

I forgot to mention - if you have any interest in seeing a reference
for (an older version of) our JavaScript DOM bindings, see
http://phrogz.net/ObjJob/hierarchy.asp?langID=11

(Boy, do I want to rewrite that site using RoR, if only for nicer URLs
:slight_smile:

(Gavin Kistner) #8

David Vallner wrote:

Prototype-based OO *is* OO, even if you don't understand it. (I'll admit
at this point I prefer the Self / IO style of prototype-based OO than
Javascript's, but that's personal preference.)

Depending on your definition of what OO means, I might disagree.

JavaScript is nicely OO in that there are Objects that have Methods and
Properties, and an implicit scope ('this') inside those methods.

If you consider classes, and especially class inheritance, to be an
important part of OO, then you're in for a surprise. Not only does the
language not support it well, but even with some dirty hacks[1] there
are still serious limitations[2] when it comes to more than one level
of inheritance.

I like Ruby more than I like JavaScript, but don't get me wrong -
JavaScript has a lot going for it. First-class functions that are also
closures, with the ability to invoke them using arbitrary scope. The
ability to reopen a 'class' and add functionality. Terse literals for
associative arrays that preserve insertion order ;).

I just wouldn't want to have to code a LARGE application in JavaScript.
(At least not ECMAScript-263 rev 3. Newer, proposed specs have some
things going for them to make them nicer.)

[1] http://phrogz.net/JS/Classes/OOPinJS.html
[1] http://phrogz.net/JS/Classes/OOPinJS2.html

(David Vallner) #9

Phrogz wrote:

If you consider classes, and especially class inheritance, to be an
important part of OO, then you're in for a surprise. Not only does the
language not support it well, but even with some dirty hacks[1] there
are still serious limitations[2] when it comes to more than one level
of inheritance.

Problem of approach? Trying to grok Javascript OO if you consider classes to be essential is a recipe to disaster. JS being prototype-based (also called classless.)

That said, I'm not really an expert on prototype-based OO, and how it's to be used correctly. The fact it's mildly esoterical, with the only other implementations that come to mind being Self (now deader than a very dead thing, and PPC / Sparc only) and IO (so undocumented it's not even funny anymore) doesn't help either, and so it's understandable that people want classes to work instead on delving into the arcana of a non-mainstream OO paradigm.

David Vallner

(Jeremy Tregunna) #10

Anyone who has a view that OO requires classes is in for a shock. Their narrow view is somewhat shocking to me to be honest. Prototype-based OO has been around for 20 years; just because you ignore it, doesn't mean it isn't there.

···

On 06-08-23, at 16:15, Phrogz wrote:

David Vallner wrote:

Prototype-based OO *is* OO, even if you don't understand it. (I'll admit
at this point I prefer the Self / IO style of prototype-based OO than
Javascript's, but that's personal preference.)

Depending on your definition of what OO means, I might disagree.

JavaScript is nicely OO in that there are Objects that have Methods and
Properties, and an implicit scope ('this') inside those methods.

If you consider classes, and especially class inheritance, to be an
important part of OO, then you're in for a surprise. Not only does the
language not support it well, but even with some dirty hacks[1] there
are still serious limitations[2] when it comes to more than one level
of inheritance.

--
Jeremy Tregunna
jtregunna@blurgle.ca

(Matthew Johnson) #11

That said, I'm not really an expert on prototype-based OO, and how it's to be used correctly. The fact it's mildly esoterical, with the only other implementations that come to mind being Self (now deader than a very dead thing, and PPC / Sparc only) and IO (so undocumented it's not even funny anymore) doesn't help either, and so it's understandable that people want classes to work instead on delving into the arcana of a non-mainstream OO paradigm.

Slate is another prototype-based language currently under development that is quite interesting. It also includes multiple dispatch and macros similar to those in lisp. It's certainly not ready for prime time, but the ideas are quite interesting...

Matthew