[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[ANN] prototype-0.1.0

Ara.T.Howard

7/12/2006 11:37:00 PM

16 Answers

Trans

7/13/2006 2:46:00 AM

0


Very nice!

The only thing I see, is that your use of the term 'prototype' betrays
a Class-based OOP background. Ie. You're usimg "prototype" as one would
"class" and "instantiate" them albiet via a deep clone. Using a neutral
term like 'object' does away with that.

a = object{ a 1; b 2; c 3 }

T.


Logan Capaldo

7/13/2006 3:04:00 AM

0


On Jul 12, 2006, at 7:37 PM, ara.t.howard@noaa.gov wrote:

> SYNOPSIS
>
> prototype.rb implements the prototype design pattern

If I may offer a "patch" to your synopsis, IMO a prototype based
object model is not a "design pattern".

SYNOPSIS

prototype.rb implements a prototype-based object model

Just my 2c.


Jeremy Tregunna

7/13/2006 4:42:00 AM

0


On 12-Jul-06, at 10:45 PM, transfire@gmail.com wrote:

>
> Very nice!
>
> The only thing I see, is that your use of the term 'prototype' betrays
> a Class-based OOP background. Ie. You're usimg "prototype" as one
> would
> "class" and "instantiate" them albiet via a deep clone. Using a
> neutral
> term like 'object' does away with that.

That is the name of the model. See: http://en.wikipedia...
Prototype-based_programming

--
Jeremy Tregunna
jtregunna@blurgle.ca


"One serious obstacle to the adoption of good programming languages
is the notion that everything has to be sacrificed for speed. In
computer languages as in life, speed kills." -- Mike Vanier


Paul Battley

7/13/2006 9:12:00 AM

0

On 13/07/06, transfire@gmail.com <transfire@gmail.com> wrote:
> The only thing I see, is that your use of the term 'prototype' betrays
> a Class-based OOP background. Ie. You're usimg "prototype" as one would
> "class" and "instantiate" them albiet via a deep clone. Using a neutral
> term like 'object' does away with that.
>
> a = object{ a 1; b 2; c 3 }

How about this:

---

require 'prototype'

def Prototype(&blk)
return Prototype.new(&blk)
end

singleton = Prototype do
@a, @b = 40, 2

def answer() @a + @b end
end

p singleton.answer

---

Paul.

Trans

7/13/2006 9:12:00 AM

0


Jeremy Tregunna wrote:
> On 12-Jul-06, at 10:45 PM, transfire@gmail.com wrote:
>
> >
> > Very nice!
> >
> > The only thing I see, is that your use of the term 'prototype' betrays
> > a Class-based OOP background. Ie. You're usimg "prototype" as one
> > would
> > "class" and "instantiate" them albiet via a deep clone. Using a
> > neutral
> > term like 'object' does away with that.
>
> That is the name of the model. See: http://en.wikipedia...
> Prototype-based_programming

I'm not sure what your point is. I'm, aware of what it is called. But,
by "model" are you referring to "Prototype" or just the style of
programming? If the former, then here too it brings with it
preconetption of class-based OOP. What I trying to get across is that
there is deeper sense to this then class-oriented programmers generally
grasp. With Prototype-based OOP, you should not start by thinking about
what is Dog. Rather you should just create a dog. Later, if you need a
different dog, you copy your first and change it as needs be. You do
not cookie-stamp a fromal prototype. In a way the term prototype is
unfortuante. Perhaps "Instance-only programming" would convey the idea
better. Of course in practice one often does create Formal entities
nonetheless --as library tools, but even so, the bottom lines is that
there should be no dichotomy between prototype and non-prototype. There
just isn't any such thing in Prototype-OOP.

T.


Ara.T.Howard

7/13/2006 2:28:00 PM

0

Ara.T.Howard

7/13/2006 2:30:00 PM

0

Ara.T.Howard

7/13/2006 2:31:00 PM

0

Jeremy Tregunna

7/13/2006 9:54:00 PM

0


On 13-Jul-06, at 5:12 AM, transfire@gmail.com wrote:

> I'm not sure what your point is. I'm, aware of what it is called. But,
> by "model" are you referring to "Prototype" or just the style of
> programming? If the former, then here too it brings with it
> preconetption of class-based OOP. What I trying to get across is that
> there is deeper sense to this then class-oriented programmers
> generally
> grasp. With Prototype-based OOP, you should not start by thinking
> about
> what is Dog. Rather you should just create a dog. Later, if you need a
> different dog, you copy your first and change it as needs be. You do
> not cookie-stamp a fromal prototype. In a way the term prototype is
> unfortuante. Perhaps "Instance-only programming" would convey the idea
> better. Of course in practice one often does create Formal entities
> nonetheless --as library tools, but even so, the bottom lines is that
> there should be no dichotomy between prototype and non-prototype.
> There
> just isn't any such thing in Prototype-OOP.

I've been working with, and assisting in development of the prototype
programming language Io for the past 2 years, I'm fully aware of the
design principals one should utilize when working within the confines
of a prototype-based language. As far as how people use it; it is my
experience that those familiar with class based OOP tend to take
about 3 weeks or so before they start to understand that you don't
define a template first; you instead define your object, and from
that make copies modifying as needed. That said however, just because
it looks like someone is writing in a class-based style, doesn't mean
they are. Generally speaking quite a few occasions will you find
yourself cloning an object which seemingly is acting like a class
(not being used itself except as a template for other objects). In
cases like this, I don't know what your problem is; this comes up
quite a bit, and is often the simpler of the two choices --
reconstruct the object based on all previous objects, or construct a
template holding basic values which then a few objects will clone
from. If you have a system like Io or NewtonScript which use a
differential inheritance model, only the changes from the object you
are cloning will be attached to your object, so you can change this
template at a later time, and anything that any object that cloned
from it hasn't changed, will receive those changes as well when
they're used. To be honest, I think this satisfies a lot of
conditions. Nobody is saying that class-based programming is without
its merits, and certainly writing in a seemingly class-based style in
a prototype language is possible, and often the simpler case.

To address your dog point more directly, incase I have to spell it
out for you. It is often the case where you have say a Kennel which
in this case, let's think of it like a data structure that houses
only Dog-like objects. It is more efficient to define (in a system
like Io or NewtonScript at least) a singular Dog object, and then
define dogs from that. I.e.,

Kennel := Object clone
Kennel dogs := list
Kennel addDog := method(aDog, dogs atIfAbsentPut(aDog))

Dog := Object clone
Dog newSlot("colour")
Dog newSlot("size")
Dog newSlot("kind")
Dog newSlot("name")

/* newSlot creates a setter slot and a value slot */

Now, if you're Kennel is going to house a lot of Newfoundland dogs,
it may be worth while to make a clone of Dog called NewfoundlandDog
(or similar); unless of course, a very small minority are going to be
anything but NewfoundlandDog's, in which case, I'd make Dog above
representative of a newfoundland (setting "kind" to "Newfoundland")
then for any non newfoundland types, i'd just as an example:

Fred := NewfoundlandDog clone
Fred setKind("Malamute")
...

And similar for other dogs (cloning Fred for other Malamutes, etc).

It makes sense in a differential inheritance system to do this kind
of thing since it eliminates a lot of repeating.

That said, I understand ruby doesn't have a differential inheritance
system, but these decisions can be applied to Ruby when using a
prototype design pattern. It just makes sense; the nice thing is,
it's not required, which is what differentiates it from class-based
programming.

> T.

--
Jeremy Tregunna
jtregunna@blurgle.ca


"One serious obstacle to the adoption of good programming languages
is the notion that everything has to be sacrificed for speed. In
computer languages as in life, speed kills." -- Mike Vanier


Ara.T.Howard

7/13/2006 10:30:00 PM

0