I am a Rustacean

  1. Is rust object oriented?
  2. If answer to 1 is yes, then please show references, where I can learn.
  3. Is there one belief in the rust community that oop is not compulsory to develop software?
  4. I wish to settle with one programming language for my life time, and after so much analysis and research, I landed on rust.
    Thanks in anticipation for your replies.
1 Like

This is demonstrably true, as there was plenty of software developed prior to the invention of OOP. Also, OOP doesn’t do anything that could break it out of the equivalence between programming languages that Church and Turing proved.

2 Likes

No, rust is not an OOP language, though it has learned from OOP languages and kept the good parts. See the rust book which has a section on OOP features in rust and explains exactly the trade-offs.

6 Likes
  • Is rust object oriented?

No. Rust is not object oriented. At least not in the sense of C++/Java etc. Although you can to a lot of what people do with such OOP languages with Rust's structs, traits, enums and macros.

  • If answer to 1 is yes, then please show references, where I can learn.

()

  • Is there one belief in the rust community that oop is not compulsory to develop software?

Never mind the Rust community. OOP is not 'compulsory' to develop software. No paradigm is compulsory, all programming languages are logical equivalent whether they be OOP, Functional, procedural, whatever. See "Turing Complete". As noted here already much software is written without OOP and much software was written before OOP became a fad.

Conversely it is possible to write in an OOP style even without a specifically OOP oriented language. In a language like C for example.

  • I wish to settle with one programming language for my life time, and after so much analysis and

That is a noble idea. However I suspect you may find yourself needing to use different languages in specific cases. For example all my client side web code is still Javascript.

1 Like
  1. No, it’s a functional language :slight_smile:
  2. Null?
  3. It isn’t compulsory to develop software, but it is one of many ways to structure a programming language.
  4. Yay! I’m a beginner myself, so it’s reassuring to know that somebody else is here with me! :slight_smile:

Ok so i wanted to do the : ) because it conveys a wildly different, chaotic-good kinda vibe, but the forum doesn’t like that and wants to make it a :slight_smile:

1 Like

Null pointers are forbidden in rust thought :slight_smile:

1 Like

That is why I answered () to question 2. Although None may have been better. With no semi-colon of course :slight_smile:

2 Likes
  • Is rust object oriented?

Not quite; Rust can express similar concepts to OOP, but does so in a different way. There is no inheritance for example, but there are traits, which serve as more powerful interfaces from other OOP languages. Rust also has a few more features from different paradigms: functional programming most notably seen in closures and iterators, imperative programming through loops and the like.

  • If answer to 1 is yes, then please show references, where I can learn.

Since it kind of is, yet it isn't, I'll show you some examples:

// A trait is the equivalent of an interface in java/etc.
trait Entity {
    // Method definitions
    fn draw();
    // Generics are really important in rust
    fn interact_with<T: Entity>(message: Message);
}

// Enums can contain data
enum Message {
    Position(Vec2),
    /* ... */
}

trait Bar {}

fn foo(unknown: Box<dyn Bar>) {
    // We don't know what the type of `unknown`'s contents
    // exactly is, but we can interact with it through the
    // the view of `Bar`, similar to upcasting. 
    /* ... */
}

fn baz(x: Option<usize>) {
    // x can be `None`, or `Some(value)`, similar to `null` 
    // in other languages. 
    // In Rust, nothing is permitted to be `null`-ish, unless
    // explicitly stated in the code. 
    if let Some(value) = x {
        println!("Got {}", value);
    } else {
        println!("Got no value.");
    }
}
  • Is there one belief in the rust community that oop is not compulsory to develop software?

If I'm interpreting this correctly, you're asking if the rust community believes that OOP is not necessary to develop software. And that's true, you definitely don't need OOP to develop software, since everything ends up becoming imperative assembly with no concept of OOP left. However, I might assume you meant to ask in the case of building scaleable software, in which case the answer is still yes, you don't necessarily need OOP. In the case of Rust, programs are expressed as a "flatter" hierarchy, with relations being shallower than in OOP languages where inheritance is very prominent. This is because the "X is aY" relationship is replaced by X can do Y.

  • I wish to settle with one programming language for my life time, and after so much analysis and research, I landed on rust.

I have to agree with other people on this thread in that it's very unlikely you'll be able to only interact with Rust for the rest of your life. After all, most software is written in languages other than Rust. However, Rust is exploring a variety of other areas, and could very well become available in nearly every setting (However its use in every project in a given area is unlikely).

2 Likes

At least one or only one? Rust is probably one of the best choices (if not the best) but it's also very instructive and interesting to try other languages sometimes. (partially for understanding why Rust is a good choice) Additionally, some better language will probably appear in your lifetime.

1 Like

That is not a realistic goal. Can you expect RUST to be relevant for your entire lifetime? hopefully, In a sense I'm interested in rust because it intends to be a language for the next 50 years.
Should you expect to work in rust exclusively throughout your entire life, never needing to learn anything else? Absolutely not.

As for the other stuff, rust isn't an oop language, but that is by choice and it has most of oop's features that it needed. It has traits which fairly covers everyone's needs.

To me, "no" seems like the wrong kind of answer to "Is Rust object-oriented?". If you have to boil it down to 1 bit, it's much closer to "yes" than "no". The section of the book @vmedea linked discusses some different definitions of OOP and how Rust does or does not satisfy them. The only one that really doesn't fit is inheritance.

I wrote this in another thread, but it seems salient enough to copy and paste:

If there is an "oriented" term for Rust as a whole, I'd be inclined to call it data oriented, but that seems simplistic. Rust is a language that supports multiple paradigms. You can write object-oriented programs in Rust. It might not be quite as convenient as in Java, but it works fine. Maybe the problem is in trying to apply terms like "procedural" and "object-oriented" to a grab bag of language features rather than to the design of a specific program. Surely a procedural program doesn't become "object-oriented" because it's written in Java.

If you design a program or library around objects that have data and behavior and interact with each other, that sounds like OOP to me. And Rust supports that just fine, without using inheritance. Does that make Rust "object-oriented"? I sure don't know. Maybe it's not as object-oriented as a language like Java that supports the same things by using inheritance. Does that matter?

(I am reminded of this comic about the nature of art.)

1 Like

Alen Kay, creator of the Smalltalk language and originator of the term "object oriented" has argued that languages like C++, Java, C# etc don't fit his definition. Sorry I don't have a link for that.

Kay's conception of OO is more like the Actor Model. Which I'm told we can do in Rust with the Actix crate.

See here: https://wiki.c2.com/?AlanKaysDefinitionOfObjectOriented

So, define OO how you like I guess.

1 Like

Rust is object-oriented, pero no mucho (common Spanish expression to say something is true but only to a certain degree.).
Technically speaking I would say Rust is a object-based language (https://en.wikipedia.org/wiki/Object-based_language), but is also fair to say it just selected the best of object-oriented.
Rust has many object-oriented features: encapsulation, polymorphism, composition. It supports objects, albeit in a different way then other languages. It does not have inheritance on the way it is classically defined, but that seems not to be a problem from what I hear from other Rustaceans . Traits are like taking the best use of inheritance and defining it in another way.

As already mentioned, the book has a whole chapter about it
https://doc.rust-lang.org/book/ch17-00-oop.html

Not only in the Rust community, but in the programming community in general. That is the case for example in C and pure functional programming languages.

If you want to use a single language for a long time, instead of just looking for OO , look for a multi-purpose , multi-paradigm language. And Rust is a good choice in this domain.

2 Likes

yeah let's all vow to write Option::None from now on :joy:

2 Likes

Fair enough, when I was in college a million years ago, OOP was mostly taught was being about inhering Donkey from Animal and things like that, and drawing huge inheritance hierarchy diagrams. C++ was especially lauded for having many different kinds of inheritance. Diamond patterns are especially fun and so flexible ! But sure it's more subtle if you want :grinning:.

I wouldn't settle with one programming language for the rest of my lifetime if I were you.
Joking aside at the least it's good to know one scripting language (like Python) in addition to Rust.

Hmm...

I know some programmers, nearing retirement age that have used only COBOL for their entire careers. Another, not so old is working with a huge code base in Fortran. A friend of mine worked for many decades only in Ada.

On the other hand, in my career it seemed I got to learn a new language with almost every new project I worked on. Ultimately I started to hate that all that was mostly a useless waste of my time. Many of those languages are now obsolete and likely kids today have not even heard of them. PL/M 86, Coral, Lucol, anyone?

Worse, it was a waste of my life because conceptually most of those language were the same. Good old procedural languages that supported "structure programming" as conceived in the 1970's. Like C. I was just having to learn to do the same thing in a different syntax with a different set of libraries to get familiar with.

Still, learning a few different languages that are predicated on different 'paradigms' of software design is a good idea. It gets you to see programming in different ways. Gives you ideas that can be used even if you end up using a different language.

So, learn:

  1. Assembler: That gets you to think about how our machines actually work. Or pretty close anyway. Which is useful in understanding what is going on with stacks and heaps in other languages.

  2. Scheme: Where everything is a list, code is data and data is code. How sneaky is that?!

  3. Haskel: Because Functional programming is a big thing and the ideas from FP are useful in other languages, like Rust.

  4. Javascript: Because despite how people like to point and laugh at it JS is a very sophisticated language that has always had features that other are only now adopting. The event driven model of JS is a useful idea, and carries over to 'async' programming in Rust and other languages.

  5. Rust: Because, well I guess we all know why here.

  6. Prolog: No idea. Apparently logic programming is a thing although I have never seen a practical use for it. Perhaps I should look again.

  7. Java: No idea. Apparently extreme Object Oriented programming/everything is an object is a thing.

I'm sure others would make different selections: Swap F# for Haskel, or swap Racket for Scheme, or add Forth for fun!

1 Like

@ZiCog Really no mentioning of logic programming in e. g. Prolog?

Ah, sorry, slipped my mind. I have added it to the list.

It did not come to mind because I have never quite understood it or see where it might be practically useful.

I guess I should also include Java or C# as extreme examples of OOP. I am loath to do so. Perhaps Smalltalk?

Nah, people have tried to implement Prolog in Rust but AFAIK nobody ever tried to implement Java in Rust, so obviously Java is not important enough to occur in your enumeration.
A fun language to look into is Scratch from MIT. I like especially the syntax rule: If the blocks fit together, you have made no syntax error. If they don't fit, you cannot put them together and are thus prevented from making any syntax error ever. Also it is the only language I personally know that is not Just-English. Just the click of a button and you can choose which human language is reflected by Scratch. Thus is embraces children from many language backgrounds, as long as they can read and type.
It is object-centered but does not know inheritance. With it's slightly more verbose brother AppInventor one can easily create Android Apps that are of real world use within a weekend (without learning any syntax except from what you know from puzzles). With its slightly less verbose brother ScratchJr., programming is accessible for children that can not yet read. Rust does not even plan to have that feature in the 2023 edition.

2 Likes

Rust is multi-paradigm.

Typically in multi-paradigm langs, you're better of learning how to blend styles together than using any one religiously in isolation.

2 Likes