News for hackers. Stuff that matters.
Re:A Rust Shaped Hole by Expurple on Wednesday July 16, 2025 @03:15PM (#44585828)
> If someone posts a patch or submits a PR to a codebase written in C, it is easier to review than any other mainstream language. There is no spooky at a distance. [..] Changes are local.

Lol, wut? What about about race conditions, null pointers indirectly propagated into functions that don't expect null, aliased pointers indirectly propagated into `restrict` functions, and the other non-local UB causes? Sadly, C's explicit control flow isn't enough to actually enable local reasoning in the way that Rust (and some other functional languages) do.

I agree that Go is decent at this. But it's still not perfect, due to "downcast from interface{}", implicit nullability, and similar fragile runtime business.

I largely agree with the rest of the post! Although Rust enables better local reasoning, it definitely has more complexity and a steeper learning curve. I don't need its manual memory management most of the time, either.

Related post about a "higer-level Rust" with less memory management: https://without.boats/blog/notes-on-a-smaller-rust/

Re:A Rust Shaped Hole by shmerl on Thursday July 17, 2025 @12:45AM (#44589763)
Yeah, and C can get unreadable fast. Obfuscated C contest is a great example: https://www.ioccc.org

But that doesn't mean it's a good idea to use such style for PRs, lol.

Re:A Rust Shaped Hole by Expurple on Thursday July 17, 2025 @02:11AM (#44590215)
That's a really weird example to give. You can write unreadable code in any language if you're determined enough
Re:A Rust Shaped Hole by shmerl on Thursday July 17, 2025 @02:22AM (#44590277)
Well, C has such contest, not every language on the other hand.
Re:A Rust Shaped Hole by staunton on Thursday July 17, 2025 @02:40AM (#44590398)
I'd guess that's mostly because C has been around long enough to be chosen for it and people who are into that kind of thing don't urgently need more than one contest, regardless of language...
Re:A Rust Shaped Hole by peppingdore on Thursday July 17, 2025 @02:14AM (#44590227)
Rust is unreadable by default
Re:A Rust Shaped Hole by shmerl on Thursday July 17, 2025 @02:21AM (#44590267)
Syntax could be less terse and abbreviated, I agree. But it's not unreadable. On the other hand some complain that Rust sometimes is too verbose, so I guess it's some balance.
Re:A Rust Shaped Hole by flohofwoe on Thursday July 17, 2025 @05:18AM (#44591345)
> But it's not unreadable.

That's just because you got used to it ;) (same as with modern C++ really, if you've used C++ long enough you become blind to its problems)

Re:A Rust Shaped Hole by sagacity on Thursday July 17, 2025 @05:44AM (#44591486)
This is completely true.

"Regular" Rust and C++ is fairly readable, but a quick Google for "Higher Kinded Types in Rust" ends up with [0]:

  fn ap<A, B, F: Fn(&A) -> B>(x: &<Self as Plug<F>>::R, arg: &<Self as Plug<A>>::R) -> <Self as Plug<B>>::R
          where Self: Plug<A> + Plug<B> + Plug<F>;
[0] https://hugopeters.me/posts/14/
Re:A Rust Shaped Hole by throwawaymaths on Thursday July 17, 2025 @11:14AM (#44594277)
verbosity is not really the same as nonreadability.

i would say the biggest factor for nonreadability is not being able to chase function calls using simple text search, with as few indirections as possible. proc macros and to a lesser degree traits make that difficult.

Re:A Rust Shaped Hole by shmerl on Thursday July 17, 2025 @11:38AM (#44594529)
Yeah. You can to use LSP to work around it for usage search (which is really helpful), but it's definitely not a human readable case if function name is obscured.
Re:A Rust Shaped Hole by whytevuhuni on Thursday July 17, 2025 @02:22AM (#44590280)
If anything I'd like an even lower-level Rust.

There's so many good high-level languages to choose from, but when you need to go low-level, there's essentially only C, C++, Rust. Maybe Zig once it reaches 1.0.

What we need isn't Rust without the borrow checker. It's C with a borrow checker, and without all the usual footguns.

Re:A Rust Shaped Hole by pjmlp on Thursday July 17, 2025 @04:10AM (#44590914)
Modula-2, Object Pascal, Ada,....

Zig is basically Modula-2 in C syntax clothing.

Re:A Rust Shaped Hole by Expurple on Thursday July 17, 2025 @03:05AM (#44590564)
> There's so many good high-level languages to choose from

We have many popular high-level languages, but I disagree that they are good. Most of them are fragile piles of crap unsuitable for writing anything larger than a throwaway script.

(In my subjective and biased assessment, which is hovewer based on professional experience)

Re:A Rust Shaped Hole by delusional on Thursday July 17, 2025 @04:02AM (#44590876)
That's an interesting opinion. Could you mention one that wasn't fragile? Just to get a sense of the shape of these classes.
Re:A Rust Shaped Hole by Expurple on Thursday July 17, 2025 @04:40AM (#44591097)
They are all fragile for different reasons: dynamic typing (that always leaks through bolted-on type hints anyway), implementation inheritance, null, exceptions, uncontrolled mutation, abuse of reflection and downcasts, weak leaky interfaces that the compiler doesn't check, no help with issues in multithreaded code, insecure defaults, poor semver practices in the ecosystem, poor tooling, fragile runtime dependencies.

I use Rust. From what I've read, Swift seems better than the others, with Typescript and Go following closely. All four happen to be widely praised in this thread.

To clarify, I don't have "professional experience" with every popular language, including Swift and Typescript too.

Re:A Rust Shaped Hole by rahkiin on Thursday July 17, 2025 @02:33AM (#44590352)
It would be an interesting excercise just to see how such a language would look.

Would modules be needed or can preprocessing work still. How more advanced will the type system need to be. And how will pointers chanhe to fix all footguns and allow static borrow checking.

Re:A Rust Shaped Hole by lelanthran on Thursday July 17, 2025 @02:57AM (#44590508)
> It would be an interesting excercise just to see how such a language would look.

I started designing one (C-with-borrow-checker) way back in 2018; never got around to finishing the design or making a MVP, but I believe you can solve maybe 90% of memory problems (use after free/double free, data racing, leaking, etc) with nothing more than some additional syntax[1] to type declarations and support for only fat arrays.

IIRC, I thought that the above (coupled with an escape hatch for self-referential and/or unsafe values) was all that was needed to prevent 90% of memory errors.

Somewhere along the way scope-creep (objects would be nice, can't leave out generics, operator overloads necessary for expressing vector math, etc) turned what would have been a small project into a very large one.

-------------------------------

[1] By additional syntax, I mean using `&` and `&&` in type declarations as a qualifier similar to how `static`, `const`, `volatile`, etc qualifiers are used.

Re:A Rust Shaped Hole by sealeck on Thursday July 17, 2025 @05:39AM (#44591454)
> What we need isn't Rust without the borrow checker. It's C with a borrow checker, and without all the usual footguns.

Which would look a lot like... Rust!

Re:A Rust Shaped Hole by whytevuhuni on Thursday July 17, 2025 @05:52AM (#44591520)
Rust is more closely related to C++ than C.

I want Rust, but without panics, without generics (aside for lifetimes), without traits and bounds (aside for lifetimes), without operator overloading, without methods on structs, without RAII, without iterators, etc.

Re:A Rust Shaped Hole by borkido on Thursday July 17, 2025 @06:03AM (#44591574)
What would the benefit be of not associating functions that operate on a struct with said struct? You would just end up with a bunch of functions that take a struct of that type as their first argument.
Re:A Rust Shaped Hole by whytevuhuni on Thursday July 17, 2025 @07:06AM (#44591915)
> You would just end up with a bunch of functions that take a struct of that type as their first argument.

I don't see that as a necessarily bad thing, it brings uniformity with the rest of the functions. I've coded with libraries like APR, Nginx's API, and GTK's GLib, and the result looks quite aesthetically pleasing too (subjective of course).

I'm also not considering this as a deal-breaker or anything. The point is not that this one particular feature makes a language complex, but rather that features like these tend to pile up, and what once looked like a simple language quickly becomes less simple due to dozens of such simple features added together. But one or two of these is fine.

Re:A Rust Shaped Hole by tialaramex on Thursday July 17, 2025 @08:31AM (#44592576)
Unlike C++ all Rust's methods already can be used this way

    '5'.is_digit(10) // Is literally the same as
    char::is_digit('5', 10) // this
Basically all a "method" is in Rust is an associated function where the first parameter has the magic keyword self instead of needing a real name and type.

Rust even has guidelines recommending you consider e.g. &self rather than having an associated function whose first argument has type &Self, but noting that you should not do this if your type has "smart pointer" behaviour where users expect to call methods on the inner value instead. For example Box and Arc provide associated functions but not methods.

Re:A Rust Shaped Hole by sealeck on Thursday July 17, 2025 @07:20AM (#44592011)
You can also just... not use any of these features. It won't be pleasant, but it's doable. And some projects _do_ do this!
Re:A Rust Shaped Hole by throwawaymaths on Thursday July 17, 2025 @11:08AM (#44594227)
except you would have macros, protocols, raii, a library system fragmented over async/noasync...
Re:A Rust Shaped Hole by DeepSeaTortoise on Thursday July 17, 2025 @12:23PM (#44595030)
I disagree. I like playing around in Rust, but it is near impossible to reason about what instructions will end up being fed to your CPU without having the compiler emit the underlying assembly.

And that makes it very difficult to understand the performance of your code. Just a few days ago I couldn't wrestle the compiler into unrolling a loop (because of a get_unchecked that was hard to reason about), dropping performance of the entire data structure to as little as 30% of a quick proof of concept implementation. The asserts are powerful tools, but only if you can figure out why the compiler is not behaving nicely and how to construct the conditions that will convince it...

Re:A Rust Shaped Hole by buzzin__ on Thursday July 17, 2025 @08:37AM (#44592646)
"C is the language that combines raw power of assembly with expressiveness of assembly."
Re:A Rust Shaped Hole by trealira on Thursday July 17, 2025 @11:58AM (#44594777)
> "C is the language that combines raw power of assembly with expressiveness of assembly."

The most expressive part of C is the syntax oriented around writing terse, side-effectful expressions that manipulate buffers, pointers and counters, with the array of precedences and the pre- and post-increments and assignment operators and short-circuiting operators. You can write stuff like this:

  while (--n > 0 && (c = getchar()) != EOF && (*s++ = c) != '\n')
      ;
  *s = '\0';
Or these snippets (taken from K&R):

  // Parsing flags for command line arguments
  while (--argc > 0 && (*++argv)[O] == '-')
      while (c = *++argv[O])
          switch (c) {
          // ...
          }

  // Last line of a buffered `getchar()` implementation 
  return (--n >= 0) ? (unsigned char) *bufp++ : EOF;
You can write other programs in C, like GUI programs and compilers, but it's not as nearly tailor made for such programs and it's basically just like assembly, like you said.
Re:A Rust Shaped Hole by dxxvi on Thursday July 17, 2025 @12:51PM (#44595364)
> What we need isn't Rust without the borrow checker. It's C with a borrow checker, and without all the usual footguns

I agree with the other comment. Then what you need is Rust without all the bells and whistles (pattern matching, Cow, Rc, Result, Option ...).

Re:A Rust Shaped Hole by amluto on Thursday July 17, 2025 @02:24AM (#44590294)
Even ignoring undefined behavior and nulls, everything in C is mutable. Action at a distance is basically the norm.
Re:A Rust Shaped Hole by BiteCode_dev on Thursday July 17, 2025 @03:30AM (#44590687)
And global states.

I remember the first time I was using gettext and wonder "wait, why do I have to switch the language for my whole program if I need it for just this request?" and realized that's because GNU gettext was made like that.

Re:A Rust Shaped Hole by amluto on Thursday July 17, 2025 @10:02AM (#44593562)
This even works across processes. The initial locale comes from environment variables, and you can’t generally rely on any particular values.

In fact, the “correct” values aren’t even portable. As far as I know, there is nothing resembling universal agreement on how to ask for what some systems call “C.UTF-8”. And, no offense to non-Americans, it’s fine [0] to spell one and one half “1,500”, but it is utterly broken to invoke this behavior by means of an environment variable that no one can quite agree on.

[0] OK, it really is ridiculous that the same string of Arabic numerals, commas and periods means different things in different places.

Re:A Rust Shaped Hole by pjmlp on Thursday July 17, 2025 @04:09AM (#44590907)
The C myth keeps being perpetuated, sadly.

And had not GNU/FSF made C the official main language for FOSS software on their manifesto, by the time when C++ was already the main userspace language across Windows, OS/2, Mac OS, BeOS, that "It is the reason for C's endurance" would be much less than it already is nowadays, where it is mostly UNIX/POSIX, embedded and some OS ABIs.

Re:A Rust Shaped Hole by Xunjin on Thursday July 17, 2025 @11:52AM (#44594703)
It's funny because that was the main argument against Rust when I introduced it at the company I worked for before, but the tool has been widely used internally ever since. Because made it easy to understand the locality PRs and how it solved most safety issues (they still need some unsafe usage).
Re:A Rust Shaped Hole by atoav on Thursday July 17, 2025 @07:02AM (#44591897)
I program both C/C++ and Rust (the latter to a lesser degree currently). Rust is far superior to C in Error locality, if you write ideomatic Rust. Most of the types of errors I make in C would have been cought at compile time in Rust.

Aside from Rusts ownership model you can use the type system to enforce certain things. A typical example is that Rust uses different String types to force programmers to deal with the pitfalls. Turns out if you have a file name in an operating system it could not be a valid string, or you could have valid Unicode text that could not be a filename. Rust having different types for OS Strings and internal Unicode means when you want to go from one to the other you need to explicitly deal with the errors or choose a strategy how to handle them.

Now you could totally implement strings within Rust in a way that wouldn't force that conversion and programmers would then yolo their way through any conversion, provided they even knew about the issue. And the resulting error would not necessarily surface where it orginated. But that would be programming Rust like C.

In my experience many C libraries will just happily gulp up any input of any remotly valid shape as if it was valid data without many devs being even aware there were cases or conversions they would have had to deal with. You recognize exceptionally good C devs by the way they avoid those pitfalls.

And these skilled C devs are like seasoned mountaineers, they watch their every step carefully. But that doesn't mean the steep north face of the mountain is the safest, fastest or most ergonomic way to get to the summit. And if you believe that C is that, you should be nowhere near that language.

Re:A Rust Shaped Hole by junebash on Friday July 18, 2025 @09:16AM (#44604331)
That blog post is pretty close to describing Swift. :)
Re:A Rust Shaped Hole by rowanG077 on Friday July 18, 2025 @02:00PM (#44607877)
I was very surprised to read this too. Local reasoning is the antithesis of C.