Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I know what traits are, both in Rust as well as in language design, better read some SIGPLAN and OOPSLA papers about traits and OOP.


I'm asking you to explain how that relates to objects and classes since I use neither of those when I use traits.


Well, you can start here:

https://en.wikipedia.org/wiki/Trait_(computer_programming)

"a trait is a concept used in object-oriented programming, which represents a set of methods that can be used to extend the functionality of a class."

Then follow on protocols as an idea of generic interfaces

https://en.wikipedia.org/wiki/Protocol_(object-oriented_prog...

Then travel back in time to 2003 and read the European Conference on Object-Oriented Programming (ECOOP) paper "Traits: Composable Units of Behaviour" for a possible view on traits long before Rust was born.

The way programming languages do information hiding, polymorphism, method/function dispatch, data modelling is also part of OOP and there are several ways to combine them.

OOP is so much more than just plain objects and classes.


The implementation of traits described in that paper is totally different from the implementation of traits in Rust. Rust has adopted an ontology and syntax familiar to programmers in object oriented programming to make accessible a form of polymorphism which is quite different.

In fact, the same concept exists in Haskell, where it is called "type classes." (In this case, I think the adoption of OO terminology is harmful to comprehension, rather than helpful). Are we to believe that Haskell is object-oriented also? Is there a language with polymorphic abstraction that is not object-oriented in your formulation?


Yes Haskell type classes are interfaces from OOP point of view.

And given time on the weekend I might try to find out the talk given by SPJ about this very issue.

Polymorphism and dynamic dispatch are part of OOP.

EDIT: Found Simon's talk

Adventure with Types in Haskell, part 1 and part 2:

https://www.youtube.com/watch?v=6COvD8oynmI

https://www.youtube.com/watch?v=brE_dyedGm0

At 1:01:01 on the first lecture he discusses how Haskell relates to OOP in regards of subtyping and generic polymorphism and how although different on the surface they share those CS concepts in their own ways.

https://www.youtube.com/watch?v=6COvD8oynmI&feature=youtu.be...


I've seen SPJ's talk. You might notice that in the moment you site, he says that OO and parametric polymorphism are both polymorphism systems. Rust and Haskell are both parametric systems, not OO systems, in SPJ's formulation (and mine). The slide is literally a venn diagram of the two concepts and the abstractions they can encode.

What is an example of a language with polymorphism you do not consider to be object oriented? I'm not really interested in being linked to media I've already seen, I'm trying to suss out what you think object oriented means. As far as I can tell, it means "polymorphism," and well - yes I think polymorphism is a great idea, but I don't think its what most people mean when they say "object-oriented."

(Also, if Haskell type classes are interfaces, then so are Rust traits. They have the same semantics. But you've already said that Rust traits are traits.)


Again, it might be concepts developed in OOP languages, but I'm still not using objects. I never said I'm not using OOP, which is a stronger claim. I said I'm not using objects.


Yes, but OOP means Object Oriented Programming.

Rust traits are easily modeled in UML, just to add another point to it.

Better stop here then.


Yes, Object Oriented Programming.

Not Object Programming. I'm not using any objects when I write Rust code, even if I'm using concepts from OOP. But yeah, we've both made our point.




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

Search: