9 ms·
I was struck by the lack of inheritance in go, that to me is brilliant. I’ve worked with C# for a decade, and I’ve yet to see a use of inheritance that wouldn’
by jaabe 8y ago
I was struck by the lack of inheritance in go, that to me is brilliant.
I’ve worked with C# for a decade, and I’ve yet to see a use of inheritance that wouldn’t have been easier to maintain in the long run without using inheritance. We’ve limited our own useage to override methods in the standard library, but even then it’s often used to implement things that are really just terrible practices. Like adding search functions for AD extension fields or increasing the timeout in one of the older web clients.
- codenesium 8y agoI'm also a c# dev but with less experience. Could you elaborate? Does the mean you copy paste shared code to all of the derived classes? I think I know why you say it's a maintenance nightmare because you start off with a method or properties that make sense in all of the derived classes but overtime the classes become less cohearant and start to develope warts and it would have been easier to modify the duplicated code.
- scanr 8y agoIt’s more that there are other ways to reuse code. Search for “composition over inheritance” in your favourite search engine for more information.
- jaabe 8y agoI think you formulate it nicely. Sometimes the things it made sense to share stop making sense. Something that means rework, sometimes you end up with a parent method which is overridden in every child, possibly because each override was spread out over a long time period and no one bothered to look outside the child. Inheritance makes sense with interfaces in C# but for the rest I think composition is just a better way of sharing.
- apta 8y agoWatch out for hype that golang authors and supporters claim without properly backing it up, there's quite a bit of it. There are other languages that have better support for composition, while still maintaining support for inheritance (e.g. Kotlin). Inheritance has its uses, as evident by the fact that Rust is considering adding support for inheritance (e.g. writing GUIs).
- steveklabnik 8y agoI’m not sure what you mean by “rust is considering adding support for inheritance”; as far as I know that’s not true. Did I forget something? Do you have a link to the proposal?
- apta 8y agoI came across it a while ago, I think it was mentioned by pcwalton or someone if I'm not mistaken, specifically citing writing GUI code as a rationale. That being said, Rust (and Java, Kotlin, Scala, C#, etc) have default interface method implementations which might alleviate some of the need for full blown inheritance, unlike golang's interfaces.
- dralley 8y agoSounds like you would find the Trait system in Rust very interesting. https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f0392c8bacf1b8919d70daddb6f6557e https://play.rust-lang.org/?version=stable&mode=debug&editio...
- skybrian 8y agoTraits are okay in principle but, as a Rust beginner, the huge number of trait implementations make browsing the api docs overwhelming. For example, the list of implementations for String don't even fit on the screen at once. [1] It seems very repetitive and I wish there were an easier way to get an overview of what functionality is available and find the right method to call. [1] https://doc.rust-lang.org/std/string/struct.String.html https://doc.rust-lang.org/std/string/struct.String.html
- Inityx 8y agoIt's not a great solution, but I've found it beneficial to lean heavily on the Rust docs search bar when looking for specific behavior. It's very fast, and fuzzy enough that it finds what I'm looking for most of the time.
- tybit 8y agoEmbedding does seem like one of the decisions Go got very right. Many languages (thinking c#, Java, c++) say they promote composition over inheritance but yet make inheritance so mmuch easier to use.
- nathanaldensr 8y agoIndeed! This has always mystified me. Why is it so easy to implement what is now considered to be an anti-pattern (inheritance) when it's so boilerplate and annoying to implement composition? Why does C# not have language support for delegating members? Why do I have to buy and use ReSharper just to generate all that boilerplate? It's a constant battle talking to "just get it done" developers about why inheritance is bad.
- danmaz74 8y agoInheritance is an anti-pattern for some. Not for others (eg me).
- collyw 8y agoAs with everything it depends how its used.
- pjmlp 8y agoInheritance is only considered an anti-pattern by some. Since the 90's, any good CS book about OOP paradigms had discussions about is-a and has-a and how to make the best use of each, depending on the desired application architecture. The thing is, such books usually aren't taught on bootcamps.
- jaabe 8y agoInheritance isn’t an anti-pattern in academia. I do part time work as an examiners for CS students, and I see their car/animal examples everywhere in introductionary courses. When we have interns, they’ll sometimes build things with inheritance. So it’s certainly still a thing. I’ve yet to see a real world use of it, where you wouldn’t have been better of not using it though. My real world is the relatively boring world of enterprise public sector software, however, and maybe I’m simply oblivious to where inheritance might be worthwhile.
- deleted 8y ago[deleted]