Liste des Groupes | Revenir à c arch |
On 9/2/2024 11:23 PM, David Brown wrote:On 02/09/2024 18:46, Stephen Fuld wrote:On 9/2/2024 1:23 AM, Terje Mathisen wrote:
I want to know about both :-)I asked about C versus Rust as Terje explicitly mentioned those two languages, but you make a good point in general.>Anyway, that is all mostly moot since I'm using Rust for this kind of programming now. :-)>
Can you talk about the advantages and disadvantages of Rust versus C?
>
And also for Rust versus C++ ?
Sure. There are certainly plenty of things that I think are a better idea in a modern programming language and that make it a good step up compared to C. My key interest is in comparison to C++ - it is a step up in some ways, a step down in others, and a step sideways in many features. But is it overall up or down, for /my/ uses?My impression - based on hearsay for Rust as I have no experience - is that the key point of Rust is memory "safety". I use scare-quotes here, since it is simply about correct use of dynamic memory and buffers.I agree that memory safety is the key point, although I gather that it has other features that many programmers like.
I don't know about reality, but that's what the salesmen say.>Is it fair to say then that Rust makes it harder to get memory management "wrong"?
It is entirely possible to have correct use of memory in C, but it is also very easy to get it wrong - especially if the developer doesn't use available tools for static and run-time checks. Modern C++, on the other hand, makes it much easier to get right. You can cause yourself extra work and risk by using more old-fashioned C++, but following modern design guides using smart pointers and containers, along with easily available tools, and you get a lot of the management of memory handled automatically for very little cost.
As an example, in C++, you can make your own types that are, as fast as I can see, much more expressive and flexible than in Rust, while also being safe to use. This requires object syntax with support for multiple constructors, operator overload, function overloads, public/private separation, and multiple inheritance (at least of methods).C++ provides a huge amount more than Rust - when I have looked at Rust, it is (still) too limited for some of what I want to do.Can you give a few examples?
Multiple inheritance can easily get really messy, especially with polymorphic types where data fields come from different ancestors, and it get even more messy with virtual inheritance. I don't think that is a good solution in more than a very few niche situations.Of course, "with great power comes great responsibility" - C++ provides many exciting ways to write a complete mess :-)Sure. I gather that templates are very powerful and potentially very useful. On the other hand, I gather that multiple inheritance is very powerful, but difficult to use and potentially very ugly, and has not been carried forward in the same way into newer languages.
snip stuff about the inadequacy of existing Rust versus C++ comparisons.Absolutely. There's things about newer languages, like Rust, Go, and Swift that I like. For example, they are designed with concurrency and multi-threading from the start, rather than an add-on. C++, as we know it today, has grown gradually, and a lot of its complexity is because of features added on rather than having been part of the original design.
To my mind, the important question is not "Should we move from C to Rust?", but "Should we move from bad C to C++, Rust, or simply to good C practices?".I understand. This brings up an important issue, that of older versus newer languages.
A newer language has several advantages. One is it can take advantage of what we have learned about language design and usage since the older language was designed. I can't underestimate this enough. While many new language features turn out to be not useful, many are.
Another is that it doesn't have to worry about support for "dusty decks", i.e. the existing base which may conform to an older version of the language, nor for "dusty brains", that is programmers who learned the older (i.e. worse) ways and keep generating new code using those ways. You mention this issue in your comments.I am in the same boat. While I like C++ and find it a lot better than C, I'd be quite happy to drop it for Rust or anything else if I found they were better.
Of course, the counter to that is that new languages have to overcome the huge "installed base" advantage of existing languages.
Let me be clear. I am not a Rust evangelist. I am just looking for a way forward that will help us make programmer easier and not to make some of the same mistakes we have made in the past. Is Rust that? Some people think so. I just want to understand more.
Les messages affichés proviennent d'usenet.