3 ms·
> 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
by 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 agoBecause you can have free functions that take plain data. So you can have methods or you can have free functions. This is why it's à la carte - you can choose if you use methods or free functions. You can choose if your data has behavior or not.
- lacampbell 10y agoRight, absolutely. I am by no means claiming rust is an OO language, just that I would consider the structs + traits thing a way of making objects. I suppose I could have been more precise - it's not an object system by itself but it certainly can be very easily used as one. I think for a systems langauge they did a very fine job in designing that part of it.
- iopq 10y agoI mean, only if you're viewing it from that point of view. A Haskell programmer would just say Rust has typeclasses.