31 ms·
What's the point of objects? I don't find myself needing objects when I code in Rust.
by iopq 10y ago
What's the point of objects? I don't find myself needing objects when I code in Rust.
- pjmlp 10y agoSo how do you use Rust without traits?
- iopq 10y agoI use Rust with traits. But I don't have classes or objects.
- pjmlp 10y agoTraits are also OOP, not all OOP == Java. In fact, traits related OO research goes back to Smalltalk variants and Lisp Object Systems.
- iopq 10y agoTraits are more like better interfaces, not classes. Rust doesn't have objects either. It's all structs.
- pjmlp 10y agoI know what traits are, both in Rust as well as in language design, better read some SIGPLAN and OOPSLA papers about traits and OOP.
- iopq 10y agoI'm asking you to explain how that relates to objects and classes since I use neither of those when I use traits.
- pjmlp 10y agoWell, you can start here: https://en.wikipedia.org/wiki/Trait_(computer_programming) 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_programming) 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.
- tatterdemalion 10y agoThe 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?
- pjmlp 10y agoYes 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=6COvD8oynmI https://www.youtube.com/watch?v=brE_dyedGm0 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&t=3661 https://www.youtube.com/watch?v=6COvD8oynmI&feature=youtu.be...
- tatterdemalion 10y agoWhat is your definition of "object system"? I'm afraid it seems open enough to include any system for polymorphism. (As an aside: I am the author of several Rust trait RFCs & I have read "Traits: Composable Units of Behaviour," though "How to make ad-hoc polymorphism less ad-hoc" is more relevant to Rust. Your smugness about this toward the other poster is not appreciated.)
- deleted 10y ago[deleted]
- lacampbell 10y ago> Your smugness about this toward the other poster is not appreciated. I don't see him being smug at all. Is it smugness to suggest reading material to someone when they've shown ignorance of a topic? People do that to me here often from time to time and I don't interpret it as "smugness".
- iopq 10y agoI don't see any links to the relevant material, just namedropping
- tatterdemalion 10y agoIt is when you make the recommendation in a tone which is didactic, patronizing, and superior. That's the definition of smug (I've also found your comments somewhat smug).
- lacampbell 10y agoIf you find it smug that's really your problem. It's a bit tiresome to see people talking about OO when they haven't educated themselves about OO at all. Which is probably why I don't like Rich Hickeys talks, incidentally.
- pjmlp 10y agoMy definition is the same as the CS literature expressed in SIGPLAN, OOPSLA and ECOOP papers, written by people doing OOP language research since the mid-70s. No need to invent my own. As for the other poster, sorry if it appears like that. I did not offended anyone and provided information where to read more about trait systems. HN comments are not big enough to provide an history of OOP systems, their similarities and differences.
- lacampbell 10y agoThe venerable master Qc Na was walking with his student, Anton. Hoping to prompt the master into a discussion, Anton said "Master, I have heard that objects are a very good thing - is this true?" Qc Na looked pityingly at his student and replied, "Foolish pupil - objects are merely a poor man's closures." Chastised, Anton took his leave from his master and returned to his cell, intent on studying closures. He carefully read the entire "Lambda: The Ultimate..." series of papers and its cousins, and implemented a small Scheme interpreter with a closure-based object system. He learned much, and looked forward to informing his master of his progress. On his next walk with Qc Na, Anton attempted to impress his master by saying "Master, I have diligently studied the matter, and now understand that objects are truly a poor man's closures." Qc Na responded by hitting Anton with his stick, saying "When will you learn? Closures are a poor man's object." At that moment, Anton became enlightened. I regard rusts structs + traits as an object system. But I understand why they chose to not mention objects at all - they don't want to conjure up images of Java boiler plate and heavy mutation, which is sadly what it means to most people now.
- deleted 10y ago[deleted]
- iopq 10y ago> I regard rusts structs + traits as an object system I don't regard them as an object system because they are à la carte, while objects tie data and behavior together
- lacampbell 10y agoà la carte in what sense? I feel like data and behaviour is very much tied together in a rust struct. With the right visibility modifiers it can be completely opaque - it's literally a black box you are sending messages to. The methods are attached to the object in my mind. But I am by no means a rust expert. I'm curious is to why you think the data and behaviour are not tied together.
- iopq 10y ago