top | item 43341499

(no title)

hehbot | 11 months ago

[flagged]

discuss

order

anymouse123456|11 months ago

Rust is not free of trade offs and you're not helping the cause the way you think you are.

Just a few off the top:

- Rust is a much more complex language than C

- Rust has a much, much slower compiler than pretty much any language out there

- Rust takes most people far longer to "feel" productive

- Rust applications are sometimes (often?) slower than comparable C applications

- Rust applications are sometimes (often?) larger than comparable C applications

You may not value these things, or you may value other things more.

That's completely fine, but please don't pretend as if Rust makes zero trade offs in exchange for the safety that people seem to value so much.

criddell|11 months ago

> helping the cause

Rust evangelism is probably the worst part of Rust. Shallow comments stating Rust’s superiority read to me like somebody who wants to tell me about Jesus.

imtringued|11 months ago

That's fair, but to me what drags C and C++ really down for me is the difficulty in building them. As I get older I just want to write the code and not mess with makefiles or CMake. I don't want starting a new project to be a "commitment" that requires me to sit down for two hours.

For me Rust isn't really competing against unchecked C. It's competing against Java and boy does the JVM suck outside of server deployments. C gets disqualified from the beginning, so what you're complaining about falls on deaf ears.

I'm personally suffering the consequences of "fast" C code every day. There are days where 30 minutes of my time are being wasted on waiting for antivirus software. Thinks that ought to take 2 seconds take 2 minutes. What's crazy is that in a world filled with C programs, you can't say with a good conscience that antivirus software is unnecessary.

checker659|11 months ago

Not to mention, modern CPUs have essentially been designed to make C code run as fast as possible.

Ygg2|11 months ago

> Rust is a much more complex language than C

Feature wise, yes. C forces you to keep a lot of irreducible complexity in your head.

> Rust has a much, much slower compiler than pretty much any language out there

True. But it doesn't matter much in my opinion. A decent PC should be able to grind any Rust project in few seconds.

> Rust applications are sometimes

Sometimes is a weasel word. C is sometimes slower than Java.

> Rust takes most people far longer to "feel" productive

C takes me more time to feel productive. I have to write code, then unit test, then property tests, then run valgrind, check ubsan is on. Make more tests. Do property testing, then fuzz testing.

Or I can write same stuff in Rust and run tests. Run miri and bigger test suite if I'm using unsafe. Maybe fuzz test.

nindalf|11 months ago

> Rust applications are sometimes (often?) slower than comparable C applications

Could you cite some examples? There are plenty of counter-examples

- ripgrep is 5-10x faster than grep (https://github.com/BurntSushi/ripgrep/blob/962d47e6a1208cf21...). There's a reason ripgrep is embedded within VS Code to power search.

- Memory-safe implementations of PNG (png, zune-png, wuffs) now dramatically outperform memory-unsafe ones (libpng, spng, stb_image) when decoding images. (https://www.reddit.com/r/rust/comments/1ha7uyi/memorysafe_pn...)

- The Rust implementation of GNU Coreutils compares favourably in performance. For example, uutils/sort outperforms coreutils/sort by 6x while working on every mainstream OS - Linux, FreeBSD, NetBSD, OpenBSD, Illumos, Redox, Android, macOS, and Windows.(https://lwn.net/Articles/1007907/)

- Android rewrote their IPC code (Binder) from C to Rust. The Rust version is within +- 1-2% of the C version (https://www.phoronix.com/news/Google-Linux-Binder-In-Rust).

- rustls outperforms OpenSSL and BoringSSL (https://www.memorysafety.org/blog/rustls-performance-outperf...)

- zlib-rs is the fastest implementation of zlib (https://www.phoronix.com/news/Zlib-rs-0.4.2)

- Advent of Code - The one C example I saw executed the first 10 days of 2024 in 36ms (https://www.reddit.com/r/adventofcode/comments/1hbcyhz/comme...), while my idiomatic Rust solutions (https://github.com/nindalf/advent) took 10.1ms. I'm not even that good, there are Rust solutions 10x faster than mine - https://github.com/maneatingape/advent-of-code-rust.

- I don't consider the benchmarks game a worthwhile comparison because they're only writing assembly, but Rust and C are comparable in speed (https://benchmarksgame-team.pages.debian.net/benchmarksgame/...)

So yes, I'm surprised by your claim of C programs "often" outperforming comparable Rust programs, but I'd be interested to know if even the "sometimes" is true. Please share if you've found any.

The other claims are questionable as well, but this one was the most easily disproven.

dralley|11 months ago

Many of these are false?

* Rust is vastly easier to get started with as a new programmer than C or C++. The quality and availability of documentation, tutorials, tooling, ease of installation, ease of dependency management, ease of writing tests, etc. Learning C basically requires learning make / cmake / meson on top of the language, and maybe Valgrind and the various sanitizers too. C's "simplicity" is not always helpful to someone getting started.

* The Rust compiler isn't particularly slow. LLVM is slow. Monomorphization hurts the language, but any other language that made the same tradeoff would see the same problems. The compiler has also gotten much much faster in the last few years and switching linkers or compiler backends makes a huge difference.

* Orgs that have studied tracked this don't find Rust to be less productive. Within a couple of months programmers tend to be just as if not more productive than they were previously with other languages. The ramp-up is probably slower than, say, Go, but it's not Scala / Haskell. And again, the tooling & built in test framework really helps with productivity.

* Rust applications are very rarely slower than comparable C applications

* Rust applications do tend to be larger than comparable C applications, but largely because of static vs. dynamic linking and larger debuginfo.

mrob|11 months ago

The best feature of C is the inconvenience of managing dependencies. This encourages a healthy mistrust of third-party code. Rust is unfortunately bundled with an excellent package manager, so it's already well on its way to NPM-style dependency hell.

kelnos|11 months ago

Can't help but agree, as much as I prefer Rust over C.

On the other hand, C definitely goes too far in to the opposite extreme. I am very tired of reinventing wheels in C because integrating third-party dependencies is even more annoying than writing and maintaining my own versions of common routines.

codr7|11 months ago

It's also very mature, not so much of a moving target.

Both aspects are something I think many developers grow to appreciate eventually.

fxtentacle|11 months ago

completely not!

(And yes, I was considering if I should shout in capslock ;) )

I have seen so many fresh starts in Rust that went great during week 1 and 2 and then they collided with the lifetime annotations and then things very quickly got very messy. Let's store a texture pointer created from an OpenGL context based on in-memory data into a HashMap...

impl<'tex,'gl,'data,'key> GlyphCache<'a> {

Yay? And then your hashmap .or_insert_with fails due to lifetime checks so you need a match on the hashmap entry and now you're doing the key search twice and performance is significantly worse than in C.

Or you need to add a library. In C that's #include and a -l linker flag. In Rust, you now need to work through this:

https://doc.rust-lang.org/cargo/reference/manifest.html

to get a valid Cargo.toml. And make sure you don't name it cargo.toml, or stuff will randomly break.

kelnos|11 months ago

> Or you need to add a library. In C that's #include and a -l linker flag. In Rust, you now need to work through [link to cargo docs]

This is just bizarre to me, the claim that dependency management is easier in C projects than in Rust. It is incredibly rare that adding a dependency to a C project is just an #include and -l flag away. What decent-sized project doesn't use autotools or cmake or meson or whatever? Adding a dependency to any of those build systems is more work than adding a single, short line to Cargo.toml.

And even if you are just using a hand-crafted makefile (no thank you, for any kind of non-trivial, cross-platform project), how do you know that dependency is present on the system? You're basically just ignoring that problem and forcing your users to deal with it.

uasi|11 months ago

Adding `foo = "*"` to Cargo.toml is as easy as adding `-l foo` to Makefile.

baq|11 months ago

Rust has three major issues:

- compile times

- compile times

- compile times

Not a problem for small utilities, but once you start pulling dependencies... pain is felt.

codr7|11 months ago

Compared to C I'd say the biggest issue is complexity, of which compile time is a consequence.

kelnos|11 months ago

Long compile times with Rust don't really bother me that much. If it's someone else's program that I just want to build and run for myself, the one-time hit of building it isn't a big deal. I can be patient.

If it's something I'm actively developing, the compile is incremental, so it doesn't take that long.

What does often take longer than I'd like is linking. I need to look into those tricks where you build all the infrequently-changing bits (like third-party dependent crates) into a shared library, and then linking is very quick. For debug builds, this could speed up my development cycle quite a bit.

anta40|11 months ago

Long compile time isn't a new issue for language with advanced features. Before Rust, it was Haskell. And before Haskell, it was C++.

And implementation wise, probably there's something to do with LLVM.

dkersten|11 months ago

Except complexity of language

DeepSeaTortoise|11 months ago

IMO these are the major downsides of Rust in descending order of importance:

- Project leadership being at the whims of the moderators

- Language complexity

- Openly embracing 3rd party libraries and ecosystems for pretty much anything

- Having to rely on esoteric design choices to wrestle the compiler into using specific optimizations

- The community embracing absurd design complexity like implementing features via extension traits in code sections separated from both where the feature is going to be used and where either the structs and traits are implemented

- A community of zealots

I think the upsides easily outcompete the downsides, but I'd really wish it'd resolve some of these issues...

LeonidasXIV|11 months ago

At least apparent complexity. See "Expert C Programming: Deep C Secrets" which creeps up on you shockingly fast because C pretends to be simple by leaving things to be undefined but in the real life things need some kind of behavior.

desdenova|11 months ago

You can ignore most of the complexity that's not inherent to the program you're trying to write.

The difference is C also lets you ignore the inherent complexity, and that's where bugs and vulnerabilities come from.

juliangmp|11 months ago

I'll take good complexity over bad simplicity any day.

baq|11 months ago

Rust makes explicit what the C standard says you can't ignore but it's up to you and not the compiler. Rust is a simpler and easier language than C in this sense.

tmtvl|11 months ago

I like the Rust ADTs and the borrow checker, but I can't stand the syntax. I just wish it had Lisp syntax, but making it myself is far beyond my abilities.

hoppp|11 months ago

That really depends what you want to do. All that security in Rust is only needed if there is a danger of hacks compromising the system.

The moment you start building something that's not exposed to the internet and hacking it has no implications, C beats it due to simplicity and speed of development .

mrweasel|11 months ago

It also depends on what you want to get away from.

I don't disagree that Rust might technically be a better option for a new project, but it's still a fairly fast moving language with an ecosystem that hasn't completely settled down. Many are increasingly turned off by the fast changing developer environments and ecosystems, and C provides you with a language and libraries that has already been around for decades and aren't likely to change much.

There are also so many programming concepts and ideas in Rust, which are all fine and useful in their own right, but they are a distraction if you don't need them. Some might say that you could just not use them, but they sneak up on you in third party libraries, code snippets, examples and suggestions from others.

Personally I find C a more cosy language, which is great for just enjoying programming for a bit.

pmontra|11 months ago

C might beat Rust at simplicity and speed of development (don't know, I never developed in Rust) but I remember why I stopped developing in C about 30 years ago: the hundreds of inevitably bug ridden lines of C to build a CGI back then (malloc, free, strcpy, etc) vs little more than string slicing and "string" . "concatenation" in Perl and forget about everything else. That could have been Python (which I didn't know about,) or the languages there were born in those years: Ruby and PHP. Even Java was simpler to write. Runtime speed was seldom a problem even in the 90s. C programs are fast to run but they are not fast to develop.

kelnos|11 months ago

> All that security in Rust is only needed if there is a danger of hacks compromising the system.

It's not just about security, it's about reliability too. If my program crashes because of a use-after-free or null pointer dereference, I'm going to be pissed off even if there aren't security implications.

I prefer Rust to C for all sorts of projects, even those that will never sit in front of a network.

dgacmu|11 months ago

Correctness is not just about security. And the threat environment to which a program may eventually be exposed is not always obvious up front.

Also, no: that's only true for some kinds of programs. Rust, c++, and go all have a much easier ecosystem for things like data structures and more complex libraries that make writing many programs much easier than in C.

The only place I find C still useful over one of the other three is embedded, mostly because of the ecosystem, and rust is catching up there also.

(This is somewhat ironic, because I teach a class in C. It remains a useful language when you want someone to quickly see the relationship between the line of code they wrote and the resulting assembly, but it's also fraught - undefined behavior lurks in many places and adds a lot of pain. I will one day switch the class to rust, but I inherited the C version and it takes a while.)

umanwizard|11 months ago

> All that security in Rust is only needed if there is a danger of hacks compromising the system.

Rust's safety features help prevent a large class of bugs. Security issues are only one kind of bug.

> C beats it due to simplicity and speed of development

C being faster to develop than Rust is a ludicrous claim.

ryukoposting|11 months ago

Not really. Rustup only ships a limited number of toolchains, with some misses that (for me) are real head-scratchers. i686-unknown-none, for example. Can't get it from rustup. I'm sure there's a way to roll your own toolchain, but Rust's docs might as well tell you to piss up a rope for how much they talk about that.

Why is this important? C is the lingua franca of digital infrastructure. Whether that's due to merit or inertia is left as an exercise for the reader. I sure hope your new project isn't meant to supplant that legacy infrastructure, 'cause if it needs to run on legacy hardware, Rust won't work.

This is an incredibly annoying constraint when you're starting a new project, and Rust won't let you because you can't target the platform you need to target. For example, I spent hours building a Rust async runtime for Zephyr, only to discover it can't run on half the platforms Zephyr supports because Rust doesn't ship support for those platforms.

moron4hire|11 months ago

> C is the lingua franca of digital infrastructure

Is it, though? It feels more like how the French saw the French language as "the" language of the world, by basically discounting as unimportant everywhere that didn't use French.

Ok, no, yeah, I see it now. The Lingua Franca is right

MaulingMonkey|11 months ago

> toolchains

Are what cargo, rustc, etc. are expected to run on. You probably meant target.

> i686-unknown-none

Is admittedly a missing target. `x86_64-unknown-none` specifies stuff like `extern "C"`'s ABI (per https://doc.rust-lang.org/rustc/platform-support/x86_64-unkn... ) which is a lot less universal/appropriate for i686, where AFAIK everyone chooses their own different incompatible ABIs - which might be the reason it's not provided? Usually you want to pick an i686-unknown-* target that aligns more closely with your own needs (e.g. your desired object/library/binary file format, abi, bootloader, ...?)

    C:\local>rustup target list | findstr i686
    i686-linux-android
    i686-pc-windows-gnu
    i686-pc-windows-gnullvm
    i686-pc-windows-msvc (installed)
    i686-unknown-freebsd
    i686-unknown-linux-gnu
    i686-unknown-linux-musl
    i686-unknown-uefi
If, truly, none of them are appropriate for your needs, that's when it's time to use a custom target (per https://doc.rust-lang.org/rustc/targets/custom.html ) and `build-std` (per https://doc.rust-lang.org/cargo/reference/unstable.html#buil... .) Using a toolchain file to pin your nightly rustc version might be appropriate (per https://rust-lang.github.io/rustup/overrides.html#the-toolch... .)

The last time I played with custom targets was on https://github.com/MaulingMonkey/rust-opendingux-test/tree/m... , using the old `xargo` instead of `build-std`. Notes.md details modifications made to make things work.

codr7|11 months ago

Not even close to true, may I ask how much experience you have with C (not C++)?

rubymamis|11 months ago

I would use Mojo - you get the type and memory safety of Rust, the simplicity of Python and the performance of C/C++.

pansa2|11 months ago

> simplicity of Python

Python isn’t simple, it’s a very complex language. And Mojo aims to be a superset of Python - if it’s simple, that’s only because it’s incomplete.