5 ms·
The newest common languages, Go and Rust, have both left objects with type hierarchies behind. Seems modern language designers think inheritance is bad. I tend
by underdeserver 3y ago
The newest common languages, Go and Rust, have both left objects with type hierarchies behind.
Seems modern language designers think inheritance is bad. I tend to agree: the relationship is so confusing to get right (is a Square a Rectangle?), that composition instead of inheritance and Go-style interfaces instance of explicit interfaces are what you actually want in almost all cases.
- kaba0 3y agoThere are problems which are not solvable nicely without inheritance. They are rare, but GUIs are the stereotypical example, where the `SomeWidget extends Node` is just the most useful abstraction to have. Also, go is modern only in age, the only remotely novel thing about it is goroutines, so I wouldn’t detract too much from its design choices.
- gpderetta 3y agoAlgol and Simula had coroutines (just to give two examples). Go just made them mainstream again.
- kaba0 3y agoCoroutines are not just the same as “virtual threads” (in a different lingo) These concurrency models can be placed on a matrix based on stackfull/stackless and based on preemptive/cooperative. I think there are/were examples for all of them — the more interesting property of goroutines (and Java’s virtual threads) is turning blocking calls into non-blocking, by using the OS’s async IO behind the scenes for everything.
- za3faran 3y agohttp://cowlark.com/2009-11-15-go/ http://cowlark.com/2009-11-15-go/ :)
- pjmlp 3y agoInterfaces also form type hierarchies.
- underdeserver 3y agoHow?
- pjmlp 3y ago1 - Interfaces are types on the type system 2 - Interfaces can be combined into type relationships 3 - Due to structural typing, an interface can extend another one by having a common method set, allowing for Liskov substitution, any implementation that takes the base interface, will also take the extended one. What Go cannot guarantee via structural typing is that the subtyping is desired and not a coincidence in method naming.