News for hackers. Stuff that matters.
Re:I stopped everything and started writing C again by ohgr on Wednesday March 12, 2025 @04:04PM (#43347134)
I’d add that the Rust code and C code will probably have the same number of bugs. The C code will likely have some vulnerabilities on top of those.

Rust doesn’t magically make the vast majority of bugs go away. Most of bugs are entirely portable!

Re:I stopped everything and started writing C again by naasking on Wednesday March 12, 2025 @04:56PM (#43347582)
I'd say whether Rust helps you reduce bugs depends on how good you are at creating abstractions and/or encoding properties in the type system.
Re:I stopped everything and started writing C again by ohgr on Wednesday March 12, 2025 @05:04PM (#43347653)
Most bugs are way above that level of abstraction and thought.
Re:I stopped everything and started writing C again by nindalf on Wednesday March 12, 2025 @05:50PM (#43348011)
[Citation needed].
Re:I stopped everything and started writing C again by codedokode on Wednesday March 12, 2025 @05:09PM (#43347699)
Rust allows to provide more information about types (generic types, pointer usage) and checks it, while in C you have to rely on doc comments and checking the code manually. Or am I wrong and C allows to specify pointer nullability, pointer ownership and array bounds?
Re:I stopped everything and started writing C again by ohgr on Wednesday March 12, 2025 @05:17PM (#43347770)
None of those things feature in any problem I deal with on a daily basis, whatever language I use.

So for example today I dealt with a synchronization issue. This turned out to not be a code bug but a human misunderstanding of a protocol specification saga, which was not possible to code into a type system of any sort. The day before was a constraint network specification error. In both cases the code was entirely irrelevant to the problem.

Literally all I deal with are human problems.

My point is Rust doesn't help with these at all, however clever you get. It is no different to C, but C will give you a superset of vulnerabilities on top of that.

Fundamentally Rust solves no problems I have. Because the problems that matter are human ones. We are too obsessed with the microscopic problems of programming languages and type systems and not concentrating on making quality software which is far more than just "Rust makes all my problems go away" because it doesn't. It kills a small class of problems which aren't relevant to a lot of domains.

(incidentally the problems above are implemented in a subset of c++)

Re:I stopped everything and started writing C again by kelnos on Wednesday March 12, 2025 @06:59PM (#43348619)
> None of those things feature in any problem I deal with on a daily basis, whatever language I use.'

I run into those things nearly daily, so... ok then.

Re:I stopped everything and started writing C again by worthless-trash on Thursday March 13, 2025 @07:30AM (#43352232)
Do not feel bad friend, It's not you.. there is definitely inconsistencies here. Maybe they work on absolutely pristine perfect codebases.
Re:I stopped everything and started writing C again by xmcqdpt2 on Thursday March 13, 2025 @07:23AM (#43352207)
> So for example today I dealt with a synchronization issue. This turned out to not be a code bug but a human misunderstanding of a protocol specification saga, which was not possible to code into a type system of any sort.

Maybe not in a reasonable language no, but there are advances in type systems that are making ever larger classes of behaviours encodable into types. For example, algebraic effects (can this function throw, call a remote service etc)

https://koka-lang.github.io/koka/doc/index.html

linear types (this method must be called only once etc)

https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/line...

dependent typing (f(1) returning a different type from f(2), verifiable at compile time),

https://fstar-lang.org/index.html

Some of these features will eventually make it to “normal” PL. For example, Scala now has dependent types,

https://dotty.epfl.ch/docs/reference/new-types/match-types.h...

and Java can support linear type checking,

https://checkerframework.org/manual/#must-call-checker

Re:I stopped everything and started writing C again by davedx on Wednesday March 12, 2025 @06:26PM (#43348318)
This is objectively nonsense
Re:I stopped everything and started writing C again by codr7 on Wednesday March 12, 2025 @08:25PM (#43349173)
Interesting use of the word 'objectively' there.
Re:I stopped everything and started writing C again by davedx on Thursday March 13, 2025 @04:05AM (#43351163)
How can it not be true? One of the primary features of the rust compiler is enforcing memory safety at compile-time. C doesn't have anything like that. There are an entire class of bugs that are impossible to implement in rust.
Re:I stopped everything and started writing C again by stouset on Thursday March 13, 2025 @10:34AM (#43353801)
Not really.

I have written a lot of C and Rust. The notion that identical projects written in both languages would have identical numbers of (or even severity of) bugs is laughable on its face.

I mean, literally just not being able to deref a NULL pointer by itself is enormous.

Re:I stopped everything and started writing C again by tialaramex on Thursday March 13, 2025 @11:53AM (#43354528)
You can dereference null pointers in Rust, it's also easy to make null pointers. The thing is I'm not surprised you didn't realise this is possible because you would never actually do this in Rust since it's obviously a bad idea.

  let p: *const i32 = std::ptr::null();  // Pointer to a signed 32-bit integer, but it's null
  unsafe { some_local = *p };            // Dereferencing the null pointer, bang
If we instead use references they're nicer to work with, don't need unsafe, perform the same, and are never null. So obviously that's what real Rust programmers almost always do.
Re:I stopped everything and started writing C again by stouset on Thursday March 13, 2025 @01:04PM (#43355224)
Of course it’s possible. I am well aware it’s possible. You can also just call into a C library that hands you a null pointer. Further, it’s wholly possible to invalidate every single one of Rust’s safety guarantees if you try hard enough.

In practice I have never encountered a null pointer in Rust. Most Rust programmers have never encountered a null pointer. For most non-FFI practical purposes you can act as if they don’t exist.

Re:I stopped everything and started writing C again by wiseowise on Thursday March 13, 2025 @01:49PM (#43355675)
>> One catches far more issues than another

> akshually they have same amount of bugs

You literally segfault by dereferencing invalid pointer.

Re:I stopped everything and started writing C again by dannymi on Thursday March 13, 2025 @03:19PM (#43356422)
I agree.

But: If you are LUCKY! The worse case is if you DON'T segfault by dereferencing invalid pointer.

Re:I stopped everything and started writing C again by kelnos on Wednesday March 12, 2025 @06:58PM (#43348607)
Vulnerabilities are bugs, so the C code will have more bugs than the Rust program.

You might say that the C and Rust code will have the same number of logic errors, but I'm not convinced that's the case either. Sure, if you just directly translate the C to Rust, maybe. But if you rewrite the C program in Rust while making good use of Rust's type system, it's likely you'll have fewer logic errors in the Rust code as well.

Rust has other nice features that will help avoid bugs you might write in a C program, like most Result-returning functions in the stdlib being marked #[must_use], or match expressions being exhaustive, to name a couple things.

Re:I stopped everything and started writing C again by tialaramex on Thursday March 13, 2025 @06:10AM (#43351798)
> most Result-returning functions in the stdlib being marked #[must_use]

Actually it's a bit cleverer than that, and some people might benefit from knowing this. The Result type itself is marked #[must_use]. If you're writing a Goat library and you are confident that just discarding a Goat is almost always a mistake regardless of the context in which they got a Goat you too should mark your Goat type #[must_use = "this `Goat` should be handled properly according to the Holy Laws of the Amazing Goat God"] and now everybody is required to do that or explicitly opt out even for their own Goat code.

Obviously don't do this for types which you can imagine reasonable people might actually discard, only the ones where every discard is a weird special case.

Types I like in Rust which help you avoid writing errors the compiler itself couldn't possibly catch:

Duration - wait are these timeouts in seconds or milliseconds? It's different on Windows? What does zero mean, forever or instant ?

std::cmp::Ordering - this Doodad is Less than the other one

OwnedFd - it's "just" a file descriptor, in C this would be an integer, except, this is always a file descriptor, it can't be "oops, we didn't open a file" or the count of lines, or anything else, we can't Add these together because that's nonsense, they're not really integers at all.

Re:I stopped everything and started writing C again by zelphirkalt on Friday March 14, 2025 @05:41AM (#43360980)
Only about 70% of high severity bugs[1]. Quite a negligible amount.

[1]: https://www.chromium.org/Home/chromium-security/memory-safet...