VoltLang / Volta

Compiler for the Volt Programming Language
151 stars 8 forks source link

Why is separating class ind struct is bad? #17

Closed bubnenkoff closed 8 years ago

bubnenkoff commented 8 years ago

I have found very interesting mention from Alexandrescu that: "Rust has two advantages I can think of: it doesn't have the struct/class split that D does". Could anybody explain why it's bad, and maybe till Volta in WIP it's not later to change it.

bhelyer commented 8 years ago

Thank you for your consideration. Do you have a link to the broader context of that quote? As is, I can't see why it's considered sub-optimal.

bubnenkoff commented 8 years ago

I decided to ask about it on d forum http://forum.dlang.org/post/fhtjjqeqtdqtbhbvvscy@forum.dlang.org

mihails-strasuns commented 8 years ago

I don't remember Andrei rationale but I also don't like struct and class separation in D. The reason is that it couples together several orthogonal semantic choices while real applications are much more versatile. Saying that classes are strictly heap types leads to hacks like scoped. Forcing magical reference semantics leads to ugly Rebindable workaround when you need to reassign const class reference. The issue with struct destructors not being run if it is allocated on heap is also indirectly caused by such split (because it was functionality not expected and thus not tested).

bubnenkoff commented 8 years ago

@Dicebot and what is modern approach to replace structures and classes?

mihails-strasuns commented 8 years ago

Define "modern" please :) For example, neither Rust nor Go have any notion of classes at all AFAIK.

Wallbraker commented 8 years ago

Yes it conflates a lot of issues...

scope is something you want tho, being able to say if can or can not keep reference/pointer to a object/memory is nice. Proper scope not D scope. The Rebindable comes from limiting const syntax and over templitization of the language.

Well at least go have solved polymorphism in a different way, so they don't need traditional classes.