Forums

Nested (or inner) classes

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Nested (or inner) classes

Postby hopscc » Sat Sep 12, 2009 5:10 am

I've added a new ticket (ticket:178) for the enhancement of providing support for nested or inner classes.

Does anyone have any comments or discussion points to make around this area ?
e.g
utility/desire/need ?
Whether its worthwhile to support java like semantics ( automatic access to instance methods/variables in enclosing class) or C# like behaviour
(specific coding idiom for same access)
Other?
...
There will probably be a patch for a simple implementation posted shortly
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Nested (or inner) classes

Postby helium » Sat Sep 12, 2009 12:28 pm

I thought Java like == inner class, C# like == nested class.
helium
 
Posts: 14

Re: Nested (or inner) classes

Postby Charles » Sat Sep 12, 2009 6:09 pm

Maybe some code examples in all three languages would be helpful. Compare and contrast Java vs. C# and then propose syntax and semantics for Cobra.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Nested (or inner) classes

Postby hopscc » Sat Sep 12, 2009 6:28 pm

C# vs java differences C# nested classes are ike C++ nested classes, not Java inner classes.

simple cobra looks pretty much as you'd expect ;
something like this
Code: Select all
# simple nested class - access from inside
class Enclosing

        class Nested
                cue init
                        base.init

                def geti as int
                        return 1

        def geti as int
                return 99

        def main
                a = Enclosing()
                assert a.geti == 99
                n=Enclosing.Nested()
                assert n.geti == 1

# slightly more involved
# multiple levels of Nested class, inferred and explicit typing
class Enclosing

        class Nested is public

                def geti as int
                        return 1

                class Nested2
                        def geti as int
                                return 2

        class NestedOther
                get geti
                        return 10

        def geti as int
                return 99

class Enc
        def main
                a = Enclosing()
                assert a.geti == 99

                en=Enclosing.Nested()
                assert en.geti == 1

                enn=Enclosing.Nested.Nested2()
                assert enn.geti == 2

                eno as Enclosing.NestedOther?
                eno = Enclosing.NestedOther()
                assert eno.geti == 10
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Nested (or inner) classes

Postby Charles » Sat Sep 12, 2009 11:13 pm

That's a handy link including the comments. Thanks.

Looks good to me.

The _boxStack you see in the Cobra compiler is there to support nested classes / structs. So you can see I tried to account for them even though I didn't have time to really do them.

-Chuck
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Nested (or inner) classes

Postby hopscc » Mon Sep 14, 2009 10:58 pm

Yah - I posted a patch for the simplest implementation against the ticket.
It uses .curBox which used _boxStack ( cleaned out the TODO comment)
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Nested (or inner) classes

Postby Charles » Tue Sep 15, 2009 2:51 am

Cool, I'll take a look.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Nested (or inner) classes

Postby Charles » Thu Sep 17, 2009 8:01 pm

Applied. Thanks.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 44 guests