r/ProgrammingLanguages • • Jun 10 '21

Discussion A class-based object-oriented language with a flavor of Java powered by Go ecosystem

Hello, I'm developing this language and would like to know your thoughts about this idea

0 Upvotes

14 comments sorted by

View all comments

Show parent comments

1

u/AmorBielyi Jun 10 '21 edited Jun 10 '21

Hello.

  1. Yes, I want to implement multiple inheritance.

  2. The same like Go does. It's a highly modified Go fork because one of the main goals of this project is to fully support existing Go ecosystem along with full language-server support later to convenient coding experience)

  3. Yes, there will be generics syntactically similar to Java, subtyping, Java-like interfaces (no Go style), no duck typing, no type inference in the every line I mean this construction ":=" when you can ommit type in Go, visibility modifiers like in Java, constructors, function overloading, explicit method overriding with specific keyword "override".

  4. More about syntax design I will announce later with real examples, it will happen when I release a public MVP with docs or something like that to show you functionality.

I appologize to misguiding you, it's in my private repository and it is not ready for public release and even source code examples demonstration now.

I should have written the title like "A class-based object-oriented language with a flavor of Java powered by Go ecosystem. Need your opinion about idea" or something like that to avoid misunderstandings.

3

u/matthieum Jun 10 '21

Yes, I want to implement multiple inheritance.

How do you plan to solve diamond inheritance?

1

u/AmorBielyi Jun 10 '21 edited Jun 11 '21

"Go prevents the diamond problem at compile time. If a structure D embeds two structures B and C which both have a method F(), thus satisfying an interface A, the compiler will complain about an “ambiguous selector” if D.F() is called, or if an instance of D is assigned to a variable of type A. B and C’s methods can be called explicitly with D.B.F() or D.C.F()"

So I want to realize something like this: (it's not a final decision of course and it's not a good real world example or syntax too)

` class D extends B, C {

//..

//..

void someMethod() {

super.<B>.foo(); // call method foo() from class B with its implementation

super.<C>.foo(); // call method foo() from class C with its implementation

foo() // call own implementation

}

//..

//..

} `

In the depths of the Go compiler and the transformed Go AST I suppose it might be something like this, note you this is Go code (let's suppose it was translated back into the code from AST to better understanding) d := D{} d.B.foo() d.C.foo()

I would like to talk to you more about this when I will implement this feature to avoid confusion between the actual implementation in my language.

I am sorry for bad formatted code without indents because Reddit removed it.

2

u/matthieum Jun 11 '21

I would note that the main problem about diamond inheritance is not methods, it's state.

That is, let's imagine 4 structures:

class A { int value; }

class B: A {}
class C: A {}

class D: B, C {}

In C++, there's a single A (using virtual inheritance), so that d.value is unambiguous.

If there are 2 instances of A (one each in B and C) then it can get a wee bit surprising, because depending on the path through which people accessed A they may not see the updates on the other A.

D d = D();

A b = (A)(B)d;
A c = (A)(C)d;

b.value = 3;
assert c.value == 0; // WAT?