News for hackers. Stuff that matters.
Re:Assorted Thoughts on Zig and Rust by k__ on Tuesday October 20, 2020 @03:11PM (#24841245)
Thanks!

I'm basically looking for a comparison of classes and ADT, I guess.

You said, applying your class-based way of doing things didn't work, so I asked myself how would you do it the ADT way.

Re:Assorted Thoughts on Zig and Rust by estebank on Tuesday October 20, 2020 @03:22PM (#24841350)
ADTs are only concerned with the "shape" of the data and what interactions you can have. It is related to classical OOP in the sense that the "interactions" you can have are equivalent to the message passing from the original conception of OOP[1].

The distinction is similar to database design in SQL: the Schema is how the data is laid out and what the relationship between tables is (ADTs) while the queries is the operations performed on them (traits). On the other hand, in OOP there's a higher reliance on encapsulation, making behavior an integral part of what the class is and using inheritance for expansion. When all you have is ADTs, you _can't_ have inheritance, so you end up using composition (which is generally considered better design) and you are more likely to rely on the creation of "new-type" container types for everything. You think of them as a way to describe what the data is, not how you interact with it.

Apologies if this is a bit hand-wavy, I'll try to write a more thoughtful answer at a later time.

[1]: https://medium.com/javascript-scene/the-forgotten-history-of...

Re:Assorted Thoughts on Zig and Rust by k__ on Tuesday October 20, 2020 @04:07PM (#24841837)
Hm, but composition over inheritence was already mainstream when I studied 10 years ago.

Also, ECS design is a thing in game development.

Are ADTs taken these concepts into language design?