3 ms·
> And tldr is yes it lends itself to a functional style Rust does a good job of supporting a functional style efficiently. It's also considered idiomatic to co
by lucozade 8y ago
> And tldr is yes it lends itself to a functional style
Rust does a good job of supporting a functional style efficiently. It's also considered idiomatic to code functionally. Probably the biggest, obvious exception is that Rust embraces mutability because it's statically safe to do so i.e. you aren't as susceptible to the traditional disadvantages of mutability.
> You do not use inheritance nor do you have objects
That's only partially true though. Rust does support interface inheritance and polymorphism in its trait system. And enums are a closed form of sub-typing. RAII is also idiomatic and I'd argue that many would class that as object-oriented.
The way I'd characterise the OO approach in Rust is that the team looked at the experiences of using OO in other languages and picked out what they considered the valuable pieces and left the dangerous ones (like implementation inheritance).
- masklinn 8y ago> That's only partially true though. Rust does support interface inheritance and polymorphism in its trait system. It supports no more than Haskell's typeclasses (rather less in fact), are typeclasses an object system? > And enums are a closed form of sub-typing. Rust enums are pretty standard sum types, a staple of statically typed functional languages. > RAII is also idiomatic and I'd argue that many would class that as object-oriented. That's defensible but setting one hell of a low bar on the concept of object orientation.
- lucozade 8y ago> are typeclasses an object system No, did someone say they were? > Rust enums are pretty standard sum types, a staple of statically typed functional languages Indeed I'm not entirely sure what your point is. Functional and OO aren't mutually exclusive.
- Annatar 8y ago"Functional and OO aren't mutually exclusive." They must by definition be. I disagree vehemently with your statement. If you were correct, then there would be absolutely no point to programming "functionally", it would be absurd. Might as well go back to programming in Java or C++, which is utterly counterproductive.
- indeyets 8y ago"functional" is a description of algorithm (or program), but not language. Languages usually have ways to program in different styles.
- Annatar 8y agoNo, functional programming is a paradigm. An algorithm is a language independent, abstract description of solving a specific task, like for instance searching or sorting.
- Jtsummers 8y agoFunctional programming and object oriented programming are (largely) orthogonal issues. It is, in fact, quite possible to combine both approaches in a language. Java and C++ are really imperative + OOP, not pure OO. The closest to pure OO are going to be languages like Smalltalk which still has some imperative concepts and some concepts from functional programming (closures and higher order functions via blocks, in particular). Scheme allows for object oriented programming, though not directly in the base language spec. You have to build out some infrastructure for it, but then it's quite effective for it.
- masklinn 8y ago> No, did someone say they were? You're implying that Rust's traits "partially" make for an object system. Given Rust's trait are essentially a restricted form of Haskell's typeclass, these would by your assertion "partially"+ make for an object system as well.
- lucozade 8y agoNo, I was stating that Rust's trait system offer functionality that supports an OO style of programming. That doesn't really have anything to do with whether one can or cannot call Haskell's typeclasses an object system.