Forums

Class

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

Class

Postby relez » Fri Jul 25, 2008 1:28 pm

Is it possibile in Cobra Lang to re-open and modify a class? This is an easy task using Ruby and is a bit more difficult but still possible with Python.
I apologize if this is a silly question but i'm not "deep" in Cobra, today :cry:
relez
 
Posts: 69

Re: Class

Postby Charles » Fri Jul 25, 2008 1:53 pm

You can extend a class like so:
Code: Select all
extend Object

    def sayHello
        print 'hello'

This is purely a compile-time phenomena, but it works pretty well.

Cobra uses the .NET/CLR class system which has some advantages including speed and the ability to push a Cobra library out to C# and VB users. However, this system is less flexible than Ruby and Python.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Class

Postby relez » Fri Jul 25, 2008 2:38 pm

Nice.
I have another questions that raises from this:
Cobra has multiple inheritance of interfaces, but it would also benefit from multiple inheritance of code.

I realize that Cobra support interfaces, so like Java, C# and others and doesn't support multiple inheritance from classes, right?

Tk u ;)
relez
 
Posts: 69

Re: Class

Postby hopscc » Fri Jul 25, 2008 10:25 pm

right Cobra (like C# and Java) only provides single inheritance.
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Class

Postby Charles » Sat Jul 26, 2008 7:12 pm

Currently, Cobra does not support multiple inheritance because it embraces the same OO constructs seen in C# and Java. As with C#, you can get around this to some extent by using extend on interfaces which themselves permit multiple inheritance:
Code: Select all
extend IShape
    def move(dx as int, dy as int)
        .x += dx
        .y += dy

But I would still like to address this shortcoming in the future. At least one person has suggested that "traits" are the way to go and I'll be taking a look at those.

I won't get to this for awhile as it will require some deep reading and consideration, and I don't want it to block many smaller things that are coming down the pipe.

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


Return to Discussion

Who is online

Users browsing this forum: No registered users and 15 guests

cron