Live data from Hacker News

Why you should, actually, rewrite some of it in Rust

unhandledexpression.com

31–40 of 300 posts

Re: Why you should, actually, rewrite some of it in Rust

#31
post #14
post #10

Earlier quoted context omitted.

Or just rewrite it in modern C. This is sane and doable in a short period of time. You just have to make sure it's modern C. (no true Scotsman)

> Or just rewrite it in modern C. This is sane and doable in a short period of time. What do you call modern C?

Isn't Go pretty much the modern C, with additions in concurrency?

Re: Why you should, actually, rewrite some of it in Rust

#32
post #7
post #3

C can be safe if you use Turing incomplete libraries that have been verified. It's the YOLO ad hock parsers that get you in trouble.

I am not sure if you are serious or not. How does verification prevent buffer overflows? It can reduce their frequency, but you can never know you got them all. They find issues in libCURL and openSSL that have existed for years. Very few people are better than the people working on those libraries. It is better to be safe by default then add risk only when you need it. I say this as a C++ developer, I think const sh…

Formal verification is not the same as a security audit. With formal verification you can prove that something is bug-free.

> They find issues in libCURL and openSSL that have existed for years

Neither of them are formally verified. https://github.com/seL4/seL4 however is formally verified.

Re: Why you should, actually, rewrite some of it in Rust

#33
post #18
post #5

If you are really worried about the security of old C code, then the safest, most portable thing to do is re-write in modern C++. This is sane and doable in a short period of time. Rust is not.

Oh no, no, no! Some people may reasonably, with some extreme care and diligence, maybe try to claim they can write safe and UB-free C code. If stars align properly. (See maybe SQLite. Seen as one of the pinnacles of crazy pedantism in C. Also, see the article about errors found recently in SQLite with fuzzing!) But with C++, it's just impossible for a human. It's too big, too quirky, too big, too wide, too deep, too…

> Oh no, no, no! Some people may reasonably, with some extreme care and diligence, maybe try to claim they can write safe and UB-free C code. If stars align properly.

Why the sarcasm?

Re: Why you should, actually, rewrite some of it in Rust

#34

Why Rust? Why not Idris? Why not Haskell? Or you know, why rewrite it at all? You could instead try and use a safe C implementation (such as gcc/clang with the sanitisers or something like https://staff.aist.go.jp/y.oiwa/FailSafeC/index-en.html ), but to be frank if I was to rewrite my programs I would use a truly modern language like the ones that I mentioned above.

All of your questions are addressed in the article.

> Why Rust? Why not Idris? Why not Haskell?

    it can easily call C code
    it can easily be called by C code (it can export C compatible functions and structures)
    it does not need a garbage collector
    if you want, it does not even need to handle allocations
    the Rust compiler can produce static and dynamic libraries, and even object files
    the Rust compiler avoids most of the memory vulnerabilities you get in C (yes, I had to mention it)

Re: Why you should, actually, rewrite some of it in Rust

#35
post #2

Or even better, Haskell!

the cool thing about rust is that you can use it for real-time programming, one example being DSP/audio. it often means no locks, nothing blocking, no dynamic allocation (malloc and most other allocators do not provide upper bounds of execution time), no recursion, and others.

haskell is not tailored for that.

of course there are other domains for which haskell is top-nocth and rust falls flat.

Re: Why you should, actually, rewrite some of it in Rust

#36
post #33
post #18

Earlier quoted context omitted.

Oh no, no, no! Some people may reasonably, with some extreme care and diligence, maybe try to claim they can write safe and UB-free C code. If stars align properly. (See maybe SQLite. Seen as one of the pinnacles of crazy pedantism in C. Also, see the article about errors found recently in SQLite with fuzzing!) But with C++, it's just impossible for a human. It's too big, too quirky, too big, too wide, too deep, too…

> Oh no, no, no! Some people may reasonably, with some extreme care and diligence, maybe try to claim they can write safe and UB-free C code. If stars align properly. Why the sarcasm?

I'm afraid I was not being sarcastic. Sorry. This is a totally honest and dead serious opinion from a long time C & C++ user. ("stars aligning" here means "you must also have luck". As I said: see SQLite.)

Re: Why you should, actually, rewrite some of it in Rust

#37
post #7

Earlier quoted context omitted.

I am not sure if you are serious or not. How does verification prevent buffer overflows? It can reduce their frequency, but you can never know you got them all. They find issues in libCURL and openSSL that have existed for years. Very few people are better than the people working on those libraries. It is better to be safe by default then add risk only when you need it. I say this as a C++ developer, I think const sh…

Formal verification is not the same as a security audit. With formal verification you can prove that something is bug-free. > They find issues in libCURL and openSSL that have existed for years Neither of them are formally verified. https://github.com/seL4/seL4 however is formally verified.

Please, step away from "formal verification" and come back to world the rest of us devs work in. I have never seen a formally verified piece of software even once.

I don't know if its too hard to do to real software or if C doesn't allow for it, or if it is just too expensive. The simple matter is that is not an option for the vast majority of projects. Unless you can make it practical, I assert it has no place in a practical discussion about preventing software issues.

Re: Why you should, actually, rewrite some of it in Rust

#38
post #31
post #14

Earlier quoted context omitted.

> Or just rewrite it in modern C. This is sane and doable in a short period of time. What do you call modern C?

Isn't Go pretty much the modern C, with additions in concurrency?

It's garbage collected. So, no.

Re: Why you should, actually, rewrite some of it in Rust

#39
post #18
post #5

If you are really worried about the security of old C code, then the safest, most portable thing to do is re-write in modern C++. This is sane and doable in a short period of time. Rust is not.

Oh no, no, no! Some people may reasonably, with some extreme care and diligence, maybe try to claim they can write safe and UB-free C code. If stars align properly. (See maybe SQLite. Seen as one of the pinnacles of crazy pedantism in C. Also, see the article about errors found recently in SQLite with fuzzing!) But with C++, it's just impossible for a human. It's too big, too quirky, too big, too wide, too deep, too…

Basically exception safety is a solved problem in Modern C++. If you use RAIIike it was meant to be used, exception safety is not that big a deal.

Re: Why you should, actually, rewrite some of it in Rust

#40
post #29

Has anyone done any in depth explorations of the safety and security of rust code vs well written C or C++?

it's all in the "well written" part. of course well written C/C++ is good. the very point of Rust (and others, like Ada) is to admit that we, programmers, cannot do good work all the time.

anyone thinking "I'll just write these 50k SLOC very well so it'll be ok" should not consider a career in programming.

Post reply on HN