David Niklas via Dng said on Mon, 1 Sep 2025 19:22:43 -0400
>On Mon, 1 Sep 2025 17:16:56 +0100
>ael <witwall3@???> wrote:
>In fact, Linus Torvalds himself said he did not want object oriented
>C++ code in the Linux Kernel. Now we're doing OO with rust!
I quote from the Google AI's answer to "is rust an oop language?"
"Rust does not fully adhere to the traditional definition of an
object-oriented programming (OOP) language, particularly due to its
lack of class-based inheritance. While it offers features that allow
for object-like structures and behaviors, it achieves these through
different mechanisms. Here's a breakdown: Encapsulation and
Polymorphism: . Rust supports encapsulation through its module system
and the pub keyword, controlling visibility of data and functions. It
also achieves polymorphism through traits, which are similar to
interfaces in other languages, allowing different types to implement a
common set of behaviors. This enables dynamic dispatch and generic
programming. Lack of Inheritance: . Unlike traditional OOP languages
like Java or C++, Rust does not have class inheritance where one struct
can inherit data fields and method implementations directly from
another. Instead, Rust emphasizes composition over inheritance, where
you embed structs within other structs to combine functionality.
Structs and impl blocks: . Rust uses structs to define data structures,
and impl blocks to associate methods with those structs. This provides
a way to define data and associated behavior, similar to objects in
OOP. In essence, Rust provides powerful tools to model data and
encapsulate functionality in a way that can feel familiar to OOP
developers, but it does so without relying on the inheritance hierarchy
that is central to classical OOP. Some might describe it as an
"object-based" language rather than strictly "object-oriented."
I learned the rudiments of Rust a couple months ago, and the preceding
description matches my memory of Rust. Phillipe Kahn's definition of
OOP is 1) Encapsulation, 2) Inheritance, and 3) Polymorphism. As far as
encapsulation, every language but assembler, Cobol, and Cshell gives
you an easy means for encapsulation, some more than others. Rust
doesn't have inheritance. Relationships can be "has a", but not "is a".
As far as polymorphism, Rust can achieve polymorphism with traits and
impl, etc. As I remember, traits have no defaults, so you have to
define everything, removing a lot of chance to make mistakes.
There may be problems with replacing C with Rust in the Linux kernel,
but I don't think surrendering to OOP is one of them.
SteveT
Steve Litt
http://444domains.com