Hacker News new | past | comments | ask | show | jobs | submit login
Why Go’s structs are superior to class-based inheritance (medium.com)
11 points by simplyianm on June 28, 2016 | hide | past | web | favorite | 2 comments

Also look at Clojure's protocols: http://clojure.org/reference/protocols

The "objects" you pass around are just data structures (maps) and protocols only purpose is enforce you call legal functions on those, but without mixing the two concepts (like Python/Ruby, where each instance is a data structure that contains both private properties and pointers to method objects, and can even modify those on-the-fly). If you want to extend at 3rd party interface at runtime you still can, but it's at the protocol level rather than instance level - better than monkeypatching.

Also, works better to implement the Component-Entity-System pattern on dynamic languages, because your objects are simpler data structures, without all the memory overhead.

I believe this (defining interfaces and passing data structures around) is "OO done right" - OO is a powerful idea but it seems we're only now figuring out how to implement it.

If by "only now" you mean 1979 or so. Flavors and CLOS have been things for quite some time now.

Applications are open for YC Winter 2020

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