Hacker News new | past | comments | ask | show | jobs | submit login

I'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.



It’s more that there are other ways to reuse code. Search for “composition over inheritance” in your favourite search engine for more information.


I 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.


Watch 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).


I’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?


I 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: