Nested classes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Nested classes

Charles Monteiro
Hi, perhaps a bit off topic, but I was wondering from those that brought
Traits to ST, what are their thoughts of the use of nested classes such as
used in Ruby and other languages.

Good idea? If so should Smalltalk integrate these? Why? Why not ?

thanks in advance

-Charles
www.nycsmalltalk.org
--
Reply | Threaded
Open this post in threaded view
|

Re: Nested classes

Mariano Martinez Peck


On Tue, Dec 21, 2010 at 6:32 AM, Charles Monteiro <[hidden email]> wrote:

Hi, perhaps a bit off topic, but I was wondering from those that brought
Traits to ST,

just by ignorance.....weren't traits invented in smalltalk? 
 
what are their thoughts of the use of nested classes such as
used in Ruby and other languages.


what are "nested classes" in ruby?
 
Good idea? If so should Smalltalk integrate these? Why? Why not ?

thanks in advance

-Charles
www.nycsmalltalk.org
--
--
View this message in context: http://forum.world.st/Nested-classes-tp3125667p3125667.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Nested classes

Charles Monteiro
the first I heard of traits was indeed I believe from a paper by Stef's group if I recall correctly. So that's exactly what I mean.

Nested classes are an organizational and a "structural" construct.

A nested class is defined from within an outer class. They are used when a class is only likely to be instantiated (used) from within another class. For example (just an example) , when you instantiate aBody you would want to instantiate two legs but two legs outside the context of a body may not make sense.

So that seems of some value.

You can also used it to simply group classes i.e. an outer class Drawing, may specify inner classes Line, Circle, Rectangle etc. To instantiate an inner class you need special access syntax in Ruby you would do something like this:

aCircle = Drawing::Circle.new

ok, that's alright if I'm using nested classes to group.

but you can also do this:

aLeg = Body::Leg.new

but wait I thought you it only made sense to instantiate a Leg from within the context of a body.

Anyhow, I sort of have mixed feelings about it i.e. if they are worth the extra overhead. Not to mention that Smalltalk's IDE's are not setup to handle them. File based IDE's of course don't care, they just care about the source representation.

-Charles
www.nycsmalltalk.org

Reply | Threaded
Open this post in threaded view
|

Re: Nested classes

Igor Stasenko
On 21 December 2010 23:21, Charles Monteiro <[hidden email]> wrote:

>
> the first I heard of traits was indeed I believe from a paper by Stef's group
> if I recall correctly. So that's exactly what I mean.
>
> Nested classes are an organizational and a "structural" construct.
>
> A nested class is defined from within an outer class. They are used when a
> class is only likely to be instantiated (used) from within another class.
> For example (just an example) , when you instantiate aBody you would want to
> instantiate two legs but two legs outside the context of a body may not make
> sense.
>
> So that seems of some value.
>

Frankly, nested classes/namespaces is userful to limit the scope of names.
From organizational/structural point of view it not so valuable.
Because there is enough ways
in smalltalk how to organize your model nicely without using extra
dimension(s), such as nested classes.


> You can also used it to simply group classes i.e. an outer class Drawing,
> may specify inner classes Line, Circle, Rectangle etc. To instantiate an
> inner class you need special access syntax in Ruby you would do something
> like this:
>
> aCircle = Drawing::Circle.new
>
> ok, that's alright if I'm using nested classes to group.
>
> but you can also do this:
>
> aLeg = Body::Leg.new
>

you can just do:
Body Leg new.

and in
Body>>#Leg
answer any class you want to play role as 'Leg'.

Or you missing double colons in the middle? :)

> but wait I thought you it only made sense to instantiate a Leg from within
> the context of a body.
>
> Anyhow, I sort of have mixed feelings about it i.e. if they are worth the
> extra overhead. Not to mention that Smalltalk's IDE's are not setup to
> handle them. File based IDE's of course don't care, they just care about the
> source representation.

This 'nested classes' to me look like nested namespace(s),  and nothing more.
I'd rather introduce namespaces in smalltalk rather than nested classes.

But while having a long background of languages which having namespaces,
i could not say that i miss them in smalltalk too much.
I can group classes using categories, and that is enough from human
perception perspective.
Limiting the visibility scope and playing all that 'public/private'
games - this is an overengineering.

My 2c

--
Best regards,
Igor Stasenko AKA sig.

Reply | Threaded
Open this post in threaded view
|

Re: Nested classes

Stefan Marr-4
In reply to this post by Charles Monteiro
Automated personal recommendation: you like Smalltalk, you like nested classes: you will probably also like: Newspeak

http://newspeaklanguage.org/


On 21 Dec 2010, at 06:32, Charles Monteiro wrote:

>
> Hi, perhaps a bit off topic, but I was wondering from those that brought
> Traits to ST, what are their thoughts of the use of nested classes such as
> used in Ruby and other languages.
>
> Good idea? If so should Smalltalk integrate these? Why? Why not ?
>
> thanks in advance
>
> -Charles
> www.nycsmalltalk.org
> --
> --
> View this message in context: http://forum.world.st/Nested-classes-tp3125667p3125667.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>

--
Stefan Marr
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgium
http://soft.vub.ac.be/~smarr
Phone: +32 2 629 2974
Fax:   +32 2 629 3525


Reply | Threaded
Open this post in threaded view
|

Re: Nested classes

Charles Monteiro
In reply to this post by Igor Stasenko
Igor:

Let me preface that I pay my bills doing VisualWorks by day and we have namespaces.

Yeah, I'm not sold on them but several languages have them and so I wondered what I was missing. In a way if you could use them to constraint the instantiation of a nested class to only occur within a outer class it may have some merit i.e. an arm can only exist in the context of a body etc, but how value does it add ? From my perspective traits adds value and its worth its cognitive overhead, not sold on nested classes.


"you can just do:
Body Leg new.

and in
Body>>#Leg
answer any class you want to play role as 'Leg'.

Or you missing double colons in the middle? :) "

I missed something here ? , in Ruby the syntax is:

Body::Leg.new

I guess you are saying that in Smalltalk I can just setup the accessors to return whatever plays the role of a Leg but part of the point is that the Leg class is defined within a Body class and I guess if you are looking a source file in Ruby that might be helpful :)

i.e.

class Body

    class Leg

        def method1

        end

   end

end

The fact that Ruby and other language developers are not used to browser categories maybe makes this helpful in some way.


Reply | Threaded
Open this post in threaded view
|

Re: Nested classes

Igor Stasenko
On 22 December 2010 00:24, Charles Monteiro <[hidden email]> wrote:

>
> Igor:
>
> Let me preface that I pay my bills doing VisualWorks by day and we have
> namespaces.
>
> Yeah, I'm not sold on them but several languages have them and so I wondered
> what I was missing. In a way if you could use them to constraint the
> instantiation of a nested class to only occur within a outer class it may
> have some merit i.e. an arm can only exist in the context of a body etc, but
> how value does it add ? From my perspective traits adds value and its worth
> its cognitive overhead, not sold on nested classes.
>
me neither

>
> "you can just do:
> Body Leg new.
>
> and in
> Body>>#Leg
> answer any class you want to play role as 'Leg'.
>
> Or you missing double colons in the middle? :) "
>
> I missed something here ? , in Ruby the syntax is:
>
> Body::Leg.new
>

sorry, i was imprecise. I meant to say 'do you miss the colons?'..
(sarcasm) :)

> I guess you are saying that in Smalltalk I can just setup the accessors to
> return whatever plays the role of a Leg but part of the point is that the
> Leg class is defined within a Body class and I guess if you are looking a
> source file in Ruby that might be helpful :)
>
> i.e.
>
> class Body
>
>    class Leg
>
>        def method1
>
>        end
>
>   end
>
> end
>
> The fact that Ruby and other language developers are not used to browser
> categories maybe makes this helpful in some way.
>

I don't think so. You can't create a class in smalltalk without
assigning a category to it,
so, a developer, who just started with smalltalk, are forced to use
categories anyways.

Yes, and the fact that nested classes systax like in Ruby or other
languages are possible,
because they using a 'source files' , which is single bloat of code.
While in smalltalk, you usually operating with single method at one
moment of time, and all browser
operations and UI are optimized around that simple idea,
so you don't need to scroll endless file with source code to find the
method or nested class you are looking for at line #10974.

>
>
> --
> View this message in context: http://forum.world.st/Nested-classes-tp3125667p3159885.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>



--
Best regards,
Igor Stasenko AKA sig.

Reply | Threaded
Open this post in threaded view
|

Re: Nested classes

Charles Monteiro
totally agreed, given all the concepts a language like Ruby borrowed from Smalltalk, that community and others refuses to pick up at least on the browser concept, I can't live without it
Reply | Threaded
Open this post in threaded view
|

Re: Nested classes

Charles Monteiro
In reply to this post by Stefan Marr-4
thanks, Eliot had mentioned Newspeak quite a while back ago, it seems that its progressing a bit, installing it now.
Reply | Threaded
Open this post in threaded view
|

Re: Nested classes

Michael Haupt-3
In reply to this post by Mariano Martinez Peck
Hi,

Am 21.12.2010 um 22:45 schrieb Mariano Martinez Peck <[hidden email]>:
> just by ignorance.....weren't traits invented in smalltalk?

no; Self had them in the Nineties, and they were there before that. The journal version of the ST traits paper has all the references.

Best,

Michael
Reply | Threaded
Open this post in threaded view
|

Re: Nested classes

Stéphane Ducasse
In reply to this post by Charles Monteiro
Charles

I do not have the energy to type all the things I would like to say. So if one day we cross at ESUG
I can take a blackboard and explain it.
Now in a nutshell
        The problem is that nested classes implies a really different organization and infrastructure.
        If we late bound classes then we should copy code (binding are shared between litearl and
        namespace).... I do not want to enter into the details.
        Then you end up with the question of "ah ok the superclass is not known at compile time"
        -> mixin infrastructure: how do I avoid to copy all the code (copy down of accessors and only using accessing....).

Then about namespaces. I do not like VW namespaces - I do not like class level import.

Now the point is not about namespaces per se. the problem is twofold:
        - do we want real modularity or just something for nameclash.
        if you want nameclash, I do not see why prefix are not simpler

        For real modularity it means that you define your code in isolation and bind the name after
        in a bind statement and that your scope protect you (for example what happen if the super class is now
        bound to a class that by accident has the same instance variables than the class you just defined).
        So you see it changes a lot.

        - Now the infrastructure (compiled, browser..... should not use Smalltalk globals
        but environment everywhere so that we can explore namespaces and modules design.

So all the people wanting namespaces should be clear
        for what for themselves first?
        what is the engineering cost?
        do they are ready to put this cost on the table? or what other improvement is less important?
        help just to get tools been able to work on a different environment.

So if you payed attention we started since 2002 or even before removing all the Smalltalk at:
and turning them in self environment, now recently we got Smalltalk globals
and even more recently we got SystemNavigation working on environment instead of hardcoding Smalltalk globals...
Having envoironment -based tools (without having namespace in the languages since this is a different issue)
will support:
        system bootstrap
        atomic loading
        compiler bootstrap
        better modular system


So let me conclude:
        - we have a vision
        - we are not sure what is the best solution (namespace vs. true module)
        - we are working on the infrastructure so that at least we can prototype some solutions

So I hope that may anwser is ok because I will not say more. 1.2 is waiting for us to get born.
Stef


>
> Hi, perhaps a bit off topic, but I was wondering from those that brought
> Traits to ST, what are their thoughts of the use of nested classes such as
> used in Ruby and other languages.
>
> Good idea? If so should Smalltalk integrate these? Why? Why not ?
>
> thanks in advance
>
> -Charles
> www.nycsmalltalk.org
> --
> --
> View this message in context: http://forum.world.st/Nested-classes-tp3125667p3125667.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>


Reply | Threaded
Open this post in threaded view
|

Re: Nested classes

Charles Monteiro
yes, answer is ok. Indeed , namespaces in VW are about name collision nothing more. It just looks nicer :). I hope I will have the cash and time to go fly to Europe, the dollar is not so good lately :) and have a more in depth discussion of this.

So go give birth, I will await the child.

-Charles
Reply | Threaded
Open this post in threaded view
|

Re: Nested classes

Stéphane Ducasse
Thanks. :)

Stef

On Dec 22, 2010, at 2:35 PM, Charles Monteiro wrote:

>
> yes, answer is ok. Indeed , namespaces in VW are about name collision nothing
> more. It just looks nicer :). I hope I will have the cash and time to go fly
> to Europe, the dollar is not so good lately :) and have a more in depth
> discussion of this.
>
> So go give birth, I will await the child.
>
> -Charles
> --
> View this message in context: http://forum.world.st/Nested-classes-tp3125667p3160624.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>