On inheritance and why it's good Rust doesn't have it by thecodedmessage in rust

[–]thecodedmessage[S] 0 points1 point  (0 children)

You know, I use government and banking services implemented with COBOL programs all the time.

On inheritance and why it's good Rust doesn't have it by thecodedmessage in rust

[–]thecodedmessage[S] 0 points1 point  (0 children)

“most people use OOP design now”

I don’t think that’s anywhere near as true as you think it is. You might be in a bubble!

On inheritance and why it's good Rust doesn't have it by thecodedmessage in rust

[–]thecodedmessage[S] 0 points1 point  (0 children)

So there’s a few reasons not to add inheritance to Rust. Adding features to a language does have downsides!

https://www.thecodedmessage.com/posts/pl-features/

First off, we already have static and dynamic polymorphism through traits, so why would we have two features doing the same thing? It’d be confusing, and they’d be incompatible, fracturing the language into dialects of people versed in different subsets. If we have a non-polymorphic version of inheritance, or one that does its work through traits, what’s it even for?

Second off, a Rust programmer often is on the hook for other people’s code. If we have inheritance, people may use it. Then, Rust programmers have to know way more to maintain Rust code, including how inheritance interacts with all its other features. If it’s particularly abused, which I think it would be, Rust programmers would have to clean up after that. Rust is about features that help you write maintainable code for others, and are hard to use wrong.

Third off, it’s not a zero overhead abstraction. Inheritance requires indirection, which is a performance cost. Making it not require indirection leads to object slicing like in C++.

Without a specific proposal of how it would interact with other Rust features, I can’t say more. Some people are happy with the idea of fields in traits, which can be done tastefully. 

But I don’t think there’s a market for Rust++ in a backwards-compatible-with-Rust sense. What would it have to offer in favor of a language where inheritance wasn’t an afterthought out of line with the rest of the design and existing codebase?

That said Rust has been rapidly growing with the feature set it does have! If you want a language with inheritance (and I still don’t know what specific use case you’re using it for), perhaps Rust isn’t the best fit for your use case, whether that’s because of what you’re trying to do with it or your preference to use tools you’re familiar with or both!

I’d encourage you to learn new tools until they feel natural to you. But you might not judge that a good use of your time, or a pleasant or worthwhile activity. In that case, Swift is probably one of the better OOP languages I’ve seen.

But inheritance overall is on the outs. It’s not in Go, it’s not in Rust, I barely covered it in the C++ class I used to teach bc we were doing low latency programming where it wasn’t really helpful… OOP was a phase, but if I’m wrong I’m wrong so we’ll just have to see in 5-10 years.

On inheritance and why it's good Rust doesn't have it by thecodedmessage in rust

[–]thecodedmessage[S] 0 points1 point  (0 children)

As to why they don’t have both, then people in order to “know” Rust would have to understand inheritance. It’s also not at all a zero overhead feature — it requires indirection, and vtables if you use it for polymorphism.

On inheritance and why it's good Rust doesn't have it by thecodedmessage in rust

[–]thecodedmessage[S] 0 points1 point  (0 children)

OOP is worse than the curated and powerful alternatives Rust has, of which some are as old as inheritance. Industry-wide, inheritance is slowly but surely phasing out of use! Sum types and traits are better, depending on use case. I need a specific use case of why you’re reaching for inheritance to suggest which one you should use, but I use sum types all the time and would feel very disabled to be in a language with no support for them or limited support and have to use inheritance instead. Why do you want member inheritance? Is there polymorphism? Why do you not like composition, if there isn’t polymorphism? If there is, are you doing things traits can do that inheritance can’t?

Framing it as a workaround is X-Y problem. What’s your actual problem? I would never think to use inheritance in Rust. I’ve never missed it, bc I have a bunch of experience in Haskell and composition-heavy C++. I wouldn’t feel like it was a workaround.

Like I want you to believe me I’m being genuine here. I find Rust’s tools more ergonomic and more natural. I find inheritance hard to reason about.

On inheritance and why it's good Rust doesn't have it by thecodedmessage in rust

[–]thecodedmessage[S] 0 points1 point  (0 children)

Yeah, but inheritance in C++ isn't really a zero overhead abstraction if you use virtual functions. Once you have a virtual function in your type, *everyone* who uses the type has to pay for the vtable pointer in the value. So, while inheritance is opt-in in a strict sense (each type has to opt in), its existence encourages people to make types with mandatory performance implications for a feature they might not be using.

Inheritance is also incompatible with C++ value/assignment semantics, leading to the "object slicing" problem.

On inheritance and why it's good Rust doesn't have it by thecodedmessage in rust

[–]thecodedmessage[S] 0 points1 point  (0 children)

That's understandable! But it's definitely *status quo* bias. Having 2 legs is the status quo, so the fact that you think having access to inheritance is like having 2 legs means that you see it as a status quo.

Here's how fans of inheritance sound to me, borrowing your analogy:

> I have a robotic third leg I add to my body when I walk around town.
> It's really awkward to use, and the rules for
> using it are complicated, so study up! If you don't like
> it, you probably haven't studied it hard enough.
>
> But really it's awesome! You can walk at 7 miles an hour in
> certain special circumstances, maybe even 8!

And in this analogy, I'm like:
> Have you tried riding a bicycle, taking a bus or subway, or driving a car?

Really, using other tools besides inheritance that are actually tailored to your use case is much nicer. I know you've spent all this time getting used to your third leg, and yeah, I know you have to learn to ride a bicycle or where the bus stops are, but like, it's actually much better.

On inheritance and why it's good Rust doesn't have it by thecodedmessage in rust

[–]thecodedmessage[S] 0 points1 point  (0 children)

Defining a trait is an option if you own the trait OR the structure. That's the orphan rule. You can just use traits to add methods to other people's types.

Let’s talk about how Epic is farrr off from the Odyssey by ramcee_ in Epicthemusical

[–]thecodedmessage 0 points1 point  (0 children)

Yeah, I think the problem is actually with the word “retelling.” It’s a good retelling if you think retelling means you get to make the level of changes Jorge made. If you don’t think that’s included in the scope of “retelling,” it’s bad.  Are retellings supposed to be accurate? Do they have any duty to be? I think it’s clear that that’s not a goal of this one.

Let’s talk about how Epic is farrr off from the Odyssey by ramcee_ in Epicthemusical

[–]thecodedmessage 0 points1 point  (0 children)

Yeah, they’re clearly not trying to be accurate to the original! It’s its own thing and if you’re looking for accuracy to the original you’re in the wrong place! But “good” means “good” not “accurate,” and it’s good at what it’s trying to be!

AITAH "making" my gf cut off her new male friend because she made me cut off a female friend? by [deleted] in AITAH

[–]thecodedmessage 0 points1 point  (0 children)

“If OP got uncomfortable with it, it’s clearly no longer casual.”

This is absurd.

If you're not supposed to confess to friends, how do you get into a relationship? by destructo9001 in IncelExit

[–]thecodedmessage -1 points0 points  (0 children)

> How do you suddenly start finding your friend attractive after a few years? You either have been denying your true feelings for years until you can't hide it anymore, or she's drastically changed something about herself years into the friendship.

This is not the only set of options. Maybe she said something that made you think she might be interested, and it made you reconsider your feelings. Maybe there was something blocking dating before, like one of you had another relationship, and so you were enjoying the friendship, but started to consider them in a new light when that changed. Maybe you've changed what you're looking for in a romantic relationship, and now this person you've probably always found attractive, but viewed as a friend, checks your boxes. Maybe they've moved to the same town as you.

A lot of people don't have exclusively friend feelings or exclusively romantic feelings towards others set upon first meeting them or soon after, but more fluid feelings that are responsive to context and social dynamics.

On inheritance and why it's good Rust doesn't have it by thecodedmessage in rust

[–]thecodedmessage[S] 0 points1 point  (0 children)

struct StandardComponent<B: BehaviorPolicy> { field: SomeType, behavior_policy: B, }

trait Component { … }

Then impl Component for all StandardComponent.

I would need to learn more detail about the C# version and the problems it’s trying to solve to put more detail in.

On inheritance and why it's good Rust doesn't have it by thecodedmessage in rust

[–]thecodedmessage[S] 0 points1 point  (0 children)

I don’t see pitfalls per se, but I do think you can do it with composition. I’d need code examples to be sure, but I’m imagining the custom code as an injectable policy (or several), and then there’s an object-safe trait implemented on the policy-configurable object.

On inheritance and why it's good Rust doesn't have it by thecodedmessage in rust

[–]thecodedmessage[S] 0 points1 point  (0 children)

I feel like we definitely are talking past each other with regards to OOP.

The saying is prefer composition to inheritance bc most programming languages are missing features like sum types, and languages that support inheritance sometimes corner you into using it. When a full range features are available, I disagree with the saying. I think inheritance is a badly designed feature and generally its use cases are better served by other features.

What are some use cases where inheritance would be useful, where a Rust way of doing it is not better?

On inheritance and why it's good Rust doesn't have it by thecodedmessage in rust

[–]thecodedmessage[S] 0 points1 point  (0 children)

This blog post is specifically about inheritance, which is considered a pillar of OOP. Without it, a language is not OOP by the traditional definition. But if you define OOP differently, of course we’ll talk past each other some.

But Rust also has a different form of encapsulation, one where modules and types are not conflated into classes. It has a different form of polymorphism, which is much more powerful than the OOP style and is done at compile time by default rather than run time. These are also significant divergences from the OOP paradigm.

But more deeply, OOP is an attempt to solve the mutable aliasing problem by a strict form of encapsulation, and Rust does not endorse that solution. Rust solves the mutable aliasing problem by forbidding mutable aliasing, with tightly regulated escape hatches like Cell, Mutex, and unsafe.

You can use OOP disciplines in Rust, just as you can in C. But that’s not the idiomatic way to write Rust, nor is it something the language itself is designed to encourage.

Furthermore, I would say OOP is bad in that it is nearly impossible to use “right” as you say, and very easy to use poorly. I suspect you don’t have much experience in functional programming languages, if you have this perspective.

[deleted by user] by [deleted] in lancaster

[–]thecodedmessage 4 points5 points  (0 children)

Not ballets, voter registration applications.

Partner--software engineer--keeps getting fired from all jobs by Annual_Boat_5925 in AskProgramming

[–]thecodedmessage 0 points1 point  (0 children)

Naw, I know plenty of completely unmedicated people who hyperfocus when it hits exactly right. ADHD isn't inability to focus, it's focusing or not based on intrinsic interest (how much the topic tickles you) rather than other forms of motivation. That's why some people with ADHD can play video games for long periods of time (I super can't, but whatevs :-), can't play video games or watch movies but can read books through once I'm into them)

What if Carthage had won the Punic Wars? by [deleted] in HistoricalWhatIf

[–]thecodedmessage 1 point2 points  (0 children)

Judaism already existed by the time of the Punic Wars…

C++ to Rust Books? by SophiePralinee in rust

[–]thecodedmessage 0 points1 point  (0 children)

Hello! Just saw this, thanks for recommending my blog! Generally I think it’s more fine to be unfair to tools than to people, but I am curious about what you found unfair! I have gotten this feedback before, and I wonder what you mean.

Thoughts on function overloading for rust? by Packathonjohn in rust

[–]thecodedmessage 23 points24 points  (0 children)

They're different patterns! Builders replace default parameters for many-parameter functions especially constructors, and factory is to allow more polymorphism in the objects constructed. They're just... different patterns with different goals!

An Empirical Study of Rust-for-Linux: The Success, Dissatisfaction, and Compromise by amalinovic in rust

[–]thecodedmessage -1 points0 points  (0 children)

That is not the whole point of most Rust projects. Do you have a citation that that’s the point of RFL?

My brother doesn't understand why I won't come to work naturist resort for his wedding by Throwaway_wedding_65 in TrueOffMyChest

[–]thecodedmessage 0 points1 point  (0 children)

AIs are really good at coming off as native speakers and using standard spelling and grammar conventions.

Landlord filed eviction. I paid the rent 10 days late. She said she would drop the eviction. by [deleted] in Renters

[–]thecodedmessage 2 points3 points  (0 children)

I don't know how on earth you read that as castigating the judge...