r/rust • • Aug 29 '24

One Of The Rust Linux Kernel Maintainers Steps Down - Cites "Nontechnical Nonsense"

https://www.phoronix.com/news/Rust-Linux-Maintainer-Step-Down
586 Upvotes

374 comments sorted by

View all comments

Show parent comments

-25

u/maxjmartin Aug 29 '24

To my knowledge Rust is dependent on C++ for at least a portion of itself. Recently I was wondering if C++ expression templates could be used as a wrapper around the internal implementation of many of Rusts data types. Simply because the simple code I wrote in C++ gave me around the performance I see with methods like zip for example in Rust. Hope that clarifies.

If Rust does depend on C++ for a portion of itself then C++ will never go away. Instead it will evolve. This has happened with other languages. JavaScript for one. C++ for another. C++ code written in Cxx20 is different than the renaissance that Cxx11 was. Which is completely different than Cxx98. In that sense C++ will I’m sure get a memory and borrow checker at compile time. Along with rewriting the standard to remove UDB.

Concepts and Traits are a good example of this evolution.

I really like OOP. But I LOVE functional programming. So for me combining the two makes for a solid workflow and environment. Basically OOP is no different from FP. The methods of an object are simply postscript function invocation using dot method invocation. Or using infix operations by passing an argument.

So having a thing that can be reasoned in that way means that it is easier to manipulate. A Vec is an object. Which can be vec.zip(), vec.push(x), or sum(vec). We naturally just think about things as objects. The concept of a bit is an object. And just think about what reason about it like that has accomplished. There will always be OOP.

25

u/[deleted] Aug 29 '24

To my knowledge Rust is dependent on C++ for at least a portion of itself.

No? Rust uses LLVM but that doesn't make Rust some sort of wrapper around C++.

-20

u/maxjmartin Aug 29 '24

I’m not saying Rust is a wrapper. I’m saying that at least a portion of it does rely on C++ or at least has in the past. Look to the need for C++ on Windows in the past. Or the fact that many crates are C++ wrappers. When is that code ever going to be rewritten in Rust?

16

u/[deleted] Aug 29 '24

What portion of the Rust language relies on C++?

And what does Rust crates binding to C++ have to do with anything? That isn't Rust being dependant on C++.

When is that code ever going to be rewritten in Rust?

  1. Lots of code is being rewritten in Rust, it's not an immediate process but there's lots of progress (see Fish for a recent example)

  2. Why does it need to be rewritten if the bindings work well?

-6

u/maxjmartin Aug 29 '24

LLVM is written in C++. So there is that. Also IIRC there are or were some C++ bindings tied to different platforms. Those I can’t say if that is true today.

I have a project I want to rewrite into Rust but can’t. Due to how a simple template can’t be utilized in Rust. Now I could rewrite almost all the rest in Rust. But that one part would have to stay in C++ and interface with the Rust code.

If old code runs solid there may also not need to be a reason to rewrite it. So having project dependencies rely on other languages does mean those languages will never die.

The best part about Rust is it remove many of the other languages complexity through abstracting it away.

9

u/Zde-G Aug 29 '24

I have a project I want to rewrite into Rust but can’t. Due to how a simple template can’t be utilized in Rust. Now I could rewrite almost all the rest in Rust. But that one part would have to stay in C++ and interface with the Rust code.

Sorry, but I don't belive it even for a nanosecond.

Would the solution done in Rust with macros and traits be more awkward and hard to support that template-based C++ solution? Absolutely.

Does it mean you couldn't switch to Rust for everything, including that part? Heck, no.

I'm also using TMP a lot and use it a lot in my $DAYJOB. And I like it.

But could I replace that 1000 LOC TMP-based solution with 10000 LOC Rust solution?

Absolutely.

Sure, it would be much larger and more awkward and harder to support, but if that's only 1% of my library then I have just made 10% of my library harder to deal with while 90% is easier to deal with. A clear win!

And I'm yet to see any problem where TMP comprises more than few percents of the whole code for a business-requested task.

-3

u/maxjmartin Aug 29 '24

Well I haven’t found a solution yet! I’m using templates for method overloads. That way I can have different classes invoke different behaviors when called by a function without needing to define inheritance. All while abstracting away the memory management and memory safety.

10

u/Zde-G Aug 29 '24

That's called traits in Rust and doesn't require any tricks. You are probably omitting some important detail in your description.

Templates are replaced with macros in Rust and sometimes using traits there could help, too. And yes, they are much more awkward to use, but as I have said: if we are talking about small part of the codebase then you can tolerate it.

Large, entirely TMP-based libraries like Eigen couldn't be ported to Rust and need full rewrite, but if your TMP-based code is only part of the larger thing (as is usually the case) then solution could be found, if you'll think deeper about it.

→ More replies (1)

8

u/geckothegeek42 Aug 29 '24

Recently I was wondering if C++ expression templates could be used as a wrapper around the internal implementation of many of Rusts data types. Simply because the simple code I wrote in C++ gave me around the performance I see with methods like zip for example in Rust.

Why would you want that? Template code is either simple or useful, rarely both. Bringing up iterators is interesting because the rust design is far and away superior to the mess of iterators and ranges in c++ that don't even come close to the functionality, composability or usability of rust iters.

Additionally your understanding of rust and c++ relationship seems woefully misinformed in a way I simply don't even know where to start correcting. Except to say completely forget everything you know about it and read up on how rust is actually implemented.

Along with rewriting the standard to remove UDB.

There is more UB in c++ ever day. It will not be removed and no one working on it wants to.

Concepts and Traits are a good example of this evolution.

Yes and concepts barely cover the functionality and safety of traits. They cannot achieve parity because of how templates work and the need to be backwards compatible. Thank you for illustrating the massive wall that c++ faces to it's evolution.

The methods of an object are simply postscript function invocation using dot method invocation.

Method call notation is not necessary nor sufficient for OOP. Nothing you've described is OOP. Saying FP is no different from OOP may be the most wrong statement possible. If it were then why do you or anyone need OOP? If that's all you want then fine rust supports it. but that's not what people are referring to. Eg, rust does not and will never support inheritance.

There will always be OOP.

Again, disagree and you have provided no justification for this. How many things last forever?

1

u/maxjmartin Aug 29 '24

The issues with C++ is also complicated by the refusal to break the ABI. Taken into consideration UDB will never go away either. But I do see the footprint being reduced over time.

We as people just think in terms of objects. The Platonic Theory of Forms, or mathematical category theory. All topics highly and with passion discussed about by advocates for particular perspectives in those fields.

So how we reason about things will always be in relation to one or more objects and how those object can be classified by conceptual traits, and manipulated by operations constrained by the classified traits of an object. Which can be done in multiple different ways.

Which bring me to your comment about traits. C++ has traits. Just like you can ensure a template argument needs to have a specific method implemented in Rust you can do that in C++ too. But the complexity in C++ is way higher. Which IMO make Rust superior in that sense.

C++’s biggest problem is its complexity. Rust on the other hand doesn’t have that level of complexity and doesn’t guarantee the ABI won’t change. Which also is IMO better.

I do think in general Rust is the better choice of the two. But that doesn’t mean C++ doesn’t have its place or does some things better depending on the needs of the project.

11

u/geckothegeek42 Aug 29 '24

But I do see the footprint being reduced over time.

It is not. Objectively. Almost Every single paper they accept into the standard adds UB and there is little interest in a paper doing the opposite.

We as people just think in terms of objects. The Platonic Theory of Forms, or mathematical category theory. All topics highly and with passion discussed about by advocates for particular perspectives in those fields.

Meaningless word salad of unjustified half claims. Forget passion, what does platonic theory of forms have to do with "class Square extends Rectangle" let alone my embedded program or my webapl?

So how we reason about things will always be in relation to one or more objects and how those object can be classified by conceptual traits, and manipulated by operations constrained by the classified traits of an object. Which can be done in multiple different ways.

You realise you are still not describing OOP right? That's fine many don't actually know what OOP is and think an object is just any thing. (Just like they think functional programming is having a lot of free functions or having higher order functions, it's not) But if you're going to seriously discuss it's merits, legacy and future as a design principle you must study up. Look into smalltalk for a start. A bit on it's own is not a value.

C++ has traits.

Close, it has concepts, which categorically cannot do all the same things a rust trait (or Haskell typeclass) can do. It's most basic failure is that I can write a function asking for a concept and then use other capabilities not covered by that concept. Thus my function is not actually strongly typed the way the signature implies. Which means the function cannot be typechecked until after monomorphization. They also don't enable runtime polymorphism. Theyre also structural rather than nominal (automatic rather than opt-in) thus having no way to check semantics on semantics only syntactic checking.

But that doesn’t mean C++ doesn’t have its place or does some things better depending on the needs of the project.

I theoretically agree but you still haven't really said and justified a place where it has its place. And that doesn't mean it will always have that place.

0

u/maxjmartin Aug 29 '24

We can disagree on specifics. And if I’m not going into enough detail as to those specifics that is probably because we are on Reddit and the size of those posts would be huge.

You can do compile time type checking and runtime polymorphism very easily in C++ with string type checking. Just write a class that invokes an interface. That interface has a single template argument that defines an object which is passed to a private struct implementation of the interface. The struct holds a pointer of the template argument. Then the struct calls another templated function of the struct data type.

Now I can write any class I want that overloads the final functional call as a friend function. That way at compile time the templated function evaluates to the right one to be invoked at runtime. And if the class doesn’t overload the templated function then nothing happens other than a simple definable default behavior that doesn’t create UB.

Oh and the class handles memory management and safety. So it is completely possible to use a monad very easily if desired in C++.

2

u/geckothegeek42 Aug 29 '24

String type checking? That mess of steps you described is very easy? Yeah right. I can't even begin to figure out whether that achieves anything I want it to.

Let me describe runtime polymorphism with traits in rust.

dyn Trait

Thank you for coming to my Ted talk

Your comments are a great example of why C++'s life is limited

1

u/maxjmartin Aug 29 '24

lol. Rust will not kill C++ anymore than C++ would or will kill C.

Rust will and is totally influencing its evolution though. Unfortunately though I don’t see C++ ever becoming as simple to use as Rust makes some things.

1

u/geckothegeek42 Aug 29 '24

Nah c++ will end itself. Whether that means it's completely gone or just a miniscule amount (yes that counts as being dead, no gotchas acting like "killed" has to mean not a single bit of c++ left, its obvious what I mean practically)

1

u/maxjmartin Aug 29 '24

Right because that happened to C…….. 🙃

2

u/LovelyKarl ureq Aug 29 '24

What do you mean Rust doesn't guarantee the ABI won't change? Rust doesn't have a (public) ABI apart from the C-ABI, which is extremely guaranteed to not change.

1

u/maxjmartin Aug 29 '24

Yes my point. As in the design of Rust tries to not create things which can’t be changed later. Which I do like about the language.

5

u/sm_greato Aug 29 '24

Rust has memory safety during runtime too. Rust, for one, has bounds checking and crashes... well normally. Plus, you have tools for reference counting and all that stuff. C++ has those too, but Rust integrates them better within itself like with all things. Rust is a cohesive language. C++ is not. It's an amalgamation of a thousand different lizards, put there over time, not a dragon.

1

u/maxjmartin Aug 29 '24

I am aware of the runtime checks for bounds and indices. But you make it sound like there is more than I am aware of which is good to hear.

I agree with pretty much everything else you said. Especially about C++ being the a language of many dialects at once.

I do wonder if over time as Rust ages if it will have a bit of the same aspect.

3

u/sm_greato Aug 29 '24

No, Rust will never succumb to the C++ effect. The developers take it slow and planned, putting all the uncertain stuff in the "unstable" category. It's never like, "Let's add this." And three years later, "Oops, we made a mistake." With C++, first the standard is made, and then the implementation. But with Rust, we actually get to see how the idea works out in the compiler itself.

2

u/maxjmartin Aug 29 '24

That is a solid point!

1

u/sm_greato Aug 30 '24

Just so you know, this is not just reasoning in the air. If you go around looking at projects, you'll find most ones in Rust require a very new—a few months old at most—compiler. But on the other hand, the most common C+⁠+ standard came out like 13 years ago.

1

u/maxjmartin Aug 30 '24

That is correct. Mostly due to the fact that C++ never prevents old code from running when new standards are created. So the is no need to update code. That is one of its benefits. But also controversial. Making one of the common arguments against it by other language fans.

1

u/sm_greato Aug 30 '24

Thing about Rust is also that code rarely gets old. Explicit workarounds, sure, but the core language features rarely get outdated.