in Search
Welcome to Neopoleon - Sign in | Join | Help
Navigation: Home | Forums | Galleries

Prothon? Prototypes? What's wrong with classes?

It remember hearing somewhere that 16.9 new blogs are created every second (don't bother trying to find that stat anywhere - I just made it up).

I think the same might be true for programming languages. It makes some sense, really - I think that many coders feel a drive to produce their own languages at some point or another. When I was younger, I certainly gave it a shot, and it was a lot of fun.

Today, though, I was getting my daily dose of slashdot (just slightly healthier than a good old fashioned crack addiction) when I came across a post about a new language called "Prothon."

I typically check these things out just because I'm curious. I'll probably never download the bits and learn the language, but a cursory view is par.

While checking this one out, I read this rather interesting tidbit on the home page for the language:

Prothon is a fresh new language that gets rid of classes altogether in the same way that Self does and regains the original practical and fun sensibility of Python.

Well, that's interesting. I don't have any formal CS training, so the concept of an OO language (which Prothon is) that doesn't use classes is news to me. Rather, Prothon uses something called a "prototype" to define objects.

The reason I'm posting this is that I'm having kind of a tough time wrapping my head around the idea of what a prototype in the OO world is. From reading the docs, it seems to me that a prototype is like a lightweight class that's defined in a procedure... or somewhere... I can't quite tell.

Are there any CS types out there who might be able to shed some light on this?

And, for those who understand the concepts, could you please explain why this is better? Or why someone might think these methods are better than just using classes? The Prothon team seems to think that the benefits are self-evident, although the code makes the concept look like a maintenance nightmare to me.

Published Saturday, March 27, 2004 4:17 AM by Rory

Filed Under:

Comments

 

Lonnie McCullough said:

This sounds a lot like prototypes in JavaScript. The idea is that an object of a specific type (Array for instance) inherits a prototype object that defines all of that type's "native" operations. The result of this is pretty much the same as a statically typed language except that type identity is defined dynamically as members can be added and removed from the prototype object as needed (and it affects all of the objects that have been or are created of that type). Its actually a very nice way to program but is a very different view of object orientation. Some would argue that languages like C++ and C# are class oriented as opposed to object oriented and that languages like JavaScript are truly object oriented as the object itself is a first class citizen that can be manipulated and modified at runtime. Hope that helps.
March 27, 2004 4:35 AM
 

Rory said:

Lonnie -

"Hope that helps."

It totally helps - thanks for responding.

"The result of this is pretty much the same as a statically typed language except that type identity is defined dynamically as members can be added and removed from the prototype object as needed"

That's kind of what I gathered, although I wasn't sure if I was right.

Mainly because I don't see how this would be a *good* thing...

Do you have any idea why people would prefer this method?
March 27, 2004 5:00 AM
 

Lonnie McCullough said:

Since a prototype based language supports no notion of type inheritance this is the only mechanism provided by these languages for type extension. In JavaScript there is actually a prototype chain (if memory serves correctly) and to add functionality, or to define a new type based on another type, we simply insert a new prototype object into the list of prototypes. So if we wanted to add a new method to Array we might do this:

function blameRory()
{
alert("I blame Rory");
}

Array.prototype.blameRory = blameRory;

and then that method becomes available on all Array objects. This is opposed to adding new instance methods like so:

a = new Array();
a.blameRory = blameRory;

The new method only appears on the a object and no where else.

If we wanted to create a new type we might do this (the syntax probably isn't right, but you get the idea):

function MyArray()
{
// this only works as expected if prototypes
// are copied by value else we are modifying
// the Array prototype
this.prototype = Array.prototype;
this.prototype.blameRory = blameRory;
}

Its actually really cool because it is a very dynamic model for object composition and code reuse, but that may all be academic as I don't know of too many apps that really exploit this feature of JavaScript. Is it better than class based languages? That doesn't really matter because its simply how these prototype based languages accomplish dynamically what those class based language do statically (with some added benefits of course).
March 27, 2004 5:39 AM
 

Duncan Mak said:

I think Self, a project done at Sun in the early 90s, is one of the pioneers in Prototype-based Object Oriented languages.
March 27, 2004 6:09 AM
 

Anonymous said:

Oh, the URL is for some papers on the Self system is here:

http://research.sun.com/research/self/papers/papers.html
March 27, 2004 6:09 AM
 

bliz said:

"It remember hearing somewhere that 16.9 new blogs are created every second (don't bother trying to find that stat anywhere - I just made it up)."

Does this include your Grandmama's blog? :)
March 27, 2004 6:28 AM
 

Scott said:

If Prothon interested you, you might also be interested in ASML from Microsoft Research.

http://research.microsoft.com/fse/asml/

Prototypes in JavaScript are cool. I used them back when I was trying to do lots of DHTML animation.
March 27, 2004 6:56 AM
 

Steve said:

That's pretty cool; I didn't know that JScript supported prototypes. Prothon lets you assign multiple prototype chains to an object; can you do the same thing in JScript?

Anyway, here's my somewhat long-winded response:

http://hyperthink.net/blog/PermaLink,guid,4152d0d6-a280-43dc-aec4-77ff07b67338.aspx
March 27, 2004 7:17 AM
 

ProtoBoy said:

There are a bounch of those langs around:

http://squirrel.sourceforge.net/
http://www.iolanguage.com/
http://bgb-sys.sourceforge.net/
http://slate.tunes.org/
http://www.worldmaker.net/tavi/index.php?page=WorldMaker.Lang.Vend


I personally really like the proto based OO are great expecially in very high level situation like scripts, in fact I think with JScript 2 they kinda screwed the language adding classes.
I'm currently playing around with Squirrel and Io.
March 27, 2004 9:26 PM
 

Juan Maiz Lulkin Flores da Cunha said:

That's the real advantage of prototype-based:

Protos are concrete classes are abstract. Human brains prefer concreteness.

Take a look at this:
http://alarmingdevelopment.org/index.php?p=5
June 20, 2005 3:08 PM
 

TrackBack said:

Steve explains
March 27, 2004 5:02 PM
New Comments to this post are disabled

About Rory

I *own* this site, you loser.