P
P
PrayHero2021-04-29 22:18:06
C++ / C#
PrayHero, 2021-04-29 22:18:06

Hype around Rust and C?

Good evening!
How critical a problem for a programmer is manual memory management, which is called a flaw in the C language? The new programming language Rast is said to be free of this shortcoming, but does the number of errors in the program depend precisely on the presence or absence of manual memory management, does not the total number of errors redistribute to other flaws in the program or programmer after forced automatic elimination of errors with boundaries, and does not Are memory bugs programmer bugs, not compiler and programming language bugs, due to inaccuracies in formulating an algorithm using the language that would have gone the other way were it not for this possibility of erroneous use of memory?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
V
Vasily Bannikov, 2021-04-29
@vabka

In order:

How critical a problem for a programmer is manual memory management, which is called a flaw in the C language?

There are a lot of bugs associated with bad memory management. For example, in chrome, about half of the CVEs are related to this. You can also remember HeartBleed in OpenSSL, which is also associated with improper memory management.
(Followed by some terribly long sentence, which I broke into parts)
The new programming language Rust is said to be devoid of this shortcoming.

Yes
Isn't the total number of errors redistributed to other shortcomings?

1. The hardest bugs to fix are bad memory management and multithreading, both of them Rust Solves
2. No, bugs are not redistributed, they're not cockroaches.
Are memory errors programmer errors?

If memory management is manual, then these are mistakes that the developer made.
If memory management is automatic (at least through GC, at least through Borrow checker), then this is a compiler / runtime / language error.
which would have flowed in a different direction were it not for this possibility of erroneous use of memory?

Not necessary.
In general, the question is very abstract and is rather an occasion for discussion. Try to give a more specific example where a memory management error turns into some other error.

D
Dmitry Belyaev, 2021-04-29
@bingo347

How critical a problem for a programmer is manual memory management, which is called a flaw in the C language?
Unfreed memory (memory leak) is the most innocuous thing that can happen.
- Doing free twice is UB
- Forgot to check the result of malloc/calloc/realloc for non-NULL, dereferenced - UB
- Honored a memory that was never written to - UB
- Dereferenced a pointer after free - UB
- Data race - UB
- .. .and a whole bunch of other things that, at best, will simply cause the program to work incorrectly, for example, it will burn your password, or transfer your money to another account 10 times.
The new programming language Rust is said to be devoid of this shortcoming.

Rust's type system guarantees only one thing - there will be no UB in safe code. A memory leak, by the way, is not UB, so memory can be leaked in safe code, in addition to cyclic reference counters, std provides many opportunities to do this directly:
https://doc.rust-lang.org/beta/std/mem/fn .forget.html
https://doc.rust-lang.org/beta/std/mem/struct.Manu...
https://doc.rust-lang.org/beta/std/boxed/struct.Bo. ..
https://doc.rust-lang.org/beta/std/vec/struct.Vec....
but does the number of errors in the program depend on the presence or absence of manual memory management
In Rust, manual memory management, like in C and C++, is simply a culture that if a structure has allocated memory, then it will free it. All sorts of Vec, Box, etc. do it in Drop . In C++, many everyday types also deallocate the memory they have allocated in the destructor. However, in Rust there is a division into safe and unsafe code, and there are more than enough opportunities for safe application programming. In C++, all code is unsafe.
Isn't the total number of errors redistributed to other program flaws?
No, it is not redistributed. A good type system can really get rid of many bugs, which makes the software generally more reliable. But you need to understand that nothing will save you from all mistakes. Banal discommunication with the customer generates a huge number of bugs.
But in Rust, you quickly get used to such a wonderful development approach as Type Driven Development, which allows you to prevent many errors even before writing code. Since Rust, I've taken this approach to other languages, and it works very well, even where the typing isn't as strong.
whether errors with memory are errors of the programmer, and not of the compiler and programming language
Of course, this is a programmer's mistake. Programmers are usually people, and people make mistakes. And it's good when there are static analysis tools that help prevent errors before the software goes into production.
PS Here is an interesting article about Rust to read: https://steveklabnik.com/writing/a-sad-day-for-rust
And what it led to: https://github.com/fafhrd91/actix-web-postmortem

C
CityCat4, 2021-04-30
@CityCat4

Hype around Rust and C?

There is no hype. Who wrote in C - he writes further. Who wants fashionable-stylish-youth - writes in Rust
manual memory management, which is called the disadvantage of the C language?

This is not a bug. It's a feature (C)
It's not a flaw in the language. This is his merit. (I'm now, of course, talking about pure C, and not about the plus). Languages ​​with auto-memory management - at least # opy chew. "Killers" C - also no less - appear and disappear like bubbles, leaving behind an unpleasant smell ...
and whether memory errors are programmer errors,

errors with memory are, of course, programmer errors. C is a low-level language, if someone does not cope with memory management, let him use other languages ​​where it is automatic.
Throwing a kitchen knife can save a person's life. And you can take it. Is the possibility of a knife to kill to death a mistake of its designer? No, because the knife is for those who know how to use it. If you don't know how - use the canteen.
Isn't the total number of errors redistributed to other flaws in the program or programmer?

No, of course, these are not cockroaches :) they were poisoned in one apartment - they were "redistributed" to others

U
uvelichitel, 2021-04-30
@uvelichitel

whether errors with memory are errors of the programmer, and not of the compiler and programming language

You try to write something in Rust. It's not just erroneous, it's not easy to compile error-free code there))

D
Denis Zagaevsky, 2021-04-29
@zagayevskiy

Reducing the number of errors of one type does not affect the number of errors of other types. So in general, the number of errors is reduced. Probably.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question