ozra / onyx-lang

The Onyx Programming Language
Other
97 stars 5 forks source link

Interfaces #72

Closed stugol closed 8 years ago

stugol commented 8 years ago

Any plan to implement interfaces (a la COM or various other languages)? Also known as pure virtual base classes in C++.

The need for interfaces is not entirely mitigated by modules and mixins. Sometimes you want to restrict an argument by functionality, but allow the implementation to vary. Values of type Enumerable contain the code of the Enumerable mixin; but interfaces allow the implementation to be defined in the class, not the module.

ozra commented 8 years ago

What about a trait (which "type-partials" are called in Onyx, that you mixin) with all functions defined as abstract? Then they have to be implemented in the type.

stugol commented 8 years ago

Is a trait the same as a Crystal module?

How are abstract functions declared? Might I suggest ?

fn() ⇥
ozra commented 8 years ago

Yes currently they behave the same, but Traits will also support instance-vars.

abstract: Simpler than that. fn() -> abstract

stugol commented 8 years ago

Suggest alternatives:

trait T
   fn1() -> abstract
   fn2() ⇥
   fn3() ->|
ozra commented 8 years ago

For the abstract case there is no need to clutter the visual space with unnecessary symbols. If there's a body, there's a body, if not, you replace it with abstract keyword. Doesn't get any cleaner than that imo. K.I.S.S. :-)

ozra commented 8 years ago

As mentioned Traits (which are Modules, except not extending themselves) are all good for this.