7 ms·
Rust is not a good C replacement (2019)
- klysm 6y agoCertainly it depends on the application.
- tick_tock_tick 6y agoWhile I'm not sold on the premise even the most fervent Rust fan has to concede that idiomatic Rust changes several times a year which is nigh unsustainable for any large codebase and no cargo fix is not a reasonable solution.
- nicoburns 6y agoJust leaving your code in the old style seems viable. My Rust code from 2017 still compiles just fine on the latest stable compiler. There are a bunch of ways I could simplify the code now (mainly enabled to non-lexical lifetimes), and I would if I needed to change the relevant section of code. But I definitely don't need to. The Rust compiler itself has lots of code in a really old style (much of it predates Rust 1.0, and originally used features that Rust no longer has). And it's generally considered to be maintainable code.
- dijit 6y agoYes and no. Granted, I'm a little bit of a newbie; but there seems to be a fervent use of the 'nightly' compiler, which obviously changes frequently. Stuff that targeted stable seems to still work. But a frightening number of crates will only work on nightly. And I'm not sure if there was a "version" that ever worked on stable, as that information isn't immediately visible on crates.io.
- dathinab 6y agoThe person is speaking about idiomatic rust code and seems to assume a large code base needs to always be updated to be in the most idiomatic stile. Most creates working on nightly only where tryfrom and async ones before that became stable. Now it's still common to find embedding and "crazy" creates (like there one which uses asm to hack in green threads) which work only on nightly. Most maintained creates work on stable by now, but it's not un-common to have some nightly only features. Honestly I haven't run into a created I wanted to use which requires nightly in a long time. The only crate which did cause me headaches in the recent year was ring (rustls,webpki) but that had gotten better.
- gpm 6y ago> like there one which uses asm to hack in green threads Hey, I implemented that at one point (crazy is a good description)! But I didn't publish it on crates.io (just gitlab). Did someone actually publish a crate that does this?
- gpm 6y agoHonestly I find not that much needs nightly anymore, but > which obviously changes frequently. Not nearly as much as you would think. Everything that doesn't need a `#![feature(...)]` at the top of your crate never changes. Most `#![feature(...)]` flags enable things actually change pretty rarely - you can definitely go years on nightly without hitting a breaking change if you're conservative in your conservative in you feature set. > And I'm not sure if there was a "version" that ever worked on stable, as that information isn't immediately visible on crates.io. That would be a nice feature to have! But I bet that you would find that if a crate currently needs nightly, it needed nightly from basically the start.
- dathinab 6y agoIt's idiomatic in rust not to chase some people's ideas about what idiomatic rust is, especially if that ideas include thinks like which libraries you use for what. If worked with rust (in a company) for over two years using rust for large code based is substainable. Sure at async fn's majorly changed for to do async IO, but that's basically it. Beside the async IO story other changes where often minor and fast to fix even without cargo fix. Also for a large code based there is zero reason to pedantically follow any new rust feature. It's actually idiomatic rust to not touch working/complete code just for some stile updates. And if you touch it anyway adding them cost you normally less than a minute. (Except async fn.)
- jbreckmckye 6y ago"Rust is still unstable, so it will therefore never be stable" "There were X new features in Rust's sixth year. I will now compare that to the count of new features in C's forty-eighth year" "People who are using new tools are interested in 'shiny' things. I am using the word 'shiny' to suggest that their motives are cognitive weakness and neophilia. It cannot be that these developers have contexts and needs I have not yet reasoned about." "I don't care about safety and segfaults, which means no-one should. I am never involved in safety critical software and therefore safety features are not useful." And finally, if I may make a cheap shot: "I would like to mount a robust defence of C based on its spec, well known for lack of Undefined Behaviour"
- santoshalper 6y agoYour first 3 points are collectively true and a fair rebuttal. That absolutely does not change the fact that the level of instability in Rust would make me very uncomfortable to use it for anything I want to last very long right now. I am not obligated to be fair to my tools when I choose them. C is profoundly stable, and that is a great asset for long-lived systems.
- derefr 6y agoRust has stable features, and unstable features. Code you wrote to target only the stable features is never going to have to change. There's a lot of Rust code in the wild (e.g. libraries) that targets unstable features. That adoption is necessary, just like drug trials are necessary: people need to actually use something, to figure out whether it's good, and/or what needs to be changed about it. Most of the time, though, an unstable feature that gets used a lot, is stabilized exactly as-is—both because the huge usage proves that people are happy with it working that way; and because there's now a lot of code in the wild depending on that feature, and it'd be a shame to break it all without an excellent justification. This means that these libraries that were "only usable on nightly" because they used a popular unstable feature, tend to become stable libraries, without having to do anything at all. And it's pretty easy to predict that this is the way things will go (just by looking at usage numbers), and so start using such libraries "early." There's very little risk of breakage introduced by doing so. It's not like there are features everyone begins depending on in Rust, that just suddenly disappear one day. Not even unstable ones. There are just (unstable) features that nobody likes or uses, and so they get changed or go away. But if nobody liked them (including you), then what does it matter whether they went away? You wouldn't have used those (again, unstable) features in the first place. Libraries wouldn't have used them either, so you wouldn't have used them even transitively. Such (unstable!) features just wouldn't exist/matter to you. If their going-away was a problem, that would mean somebody liked them enough to put them into something crucial... which means they weren't that unpopular after all, and shouldn't go away. (Or, at least, it means the author of a critical library is stubborn/malicious, and in need of either a stern talking-to or a project-fork.) It's basically the same as having pre-1.0 packages in a package ecosystem. The popular ones mature. The unpopular ones sometimes mature, and sometimes die. But the unpopular ones are unpopular, so it's very unlikely you were depending on them. (And if you were, you knew exactly what you were getting yourself into.) So what does it matter if they die?
- pixelbath 6y agoLink to previous discussion when this was posted in 2019, along with some comments from the author (I guess it was considered inflammatory enough to be flagged): https://news.ycombinator.com/item?id=19482669 https://news.ycombinator.com/item?id=19482669
- fortran77 6y agoIt's astounding that was flagged and the moderators left it flagged. Why can't we criticize Rust here?
- gpm 6y agoIt's poorly argued flamebait. I probably flagged it back then, and I definitely flagged it just now. Go look at the old discussion for lots of examples of why it is poorly argued. If they argued as poorly against C I would probably flag that too.
- platinumrad 6y agoI regularly see completely misinformed statements about C on this site and none of them have ever been flagged.
- platinumrad 6y agoProbably because the criticism was considered to be low quality. However, most programming language related criticism around here is low quality to be frank, but only criticism against certain languages is held to this standard.
- jonahbenton 6y agoD almost certainly is the "C replacement" he would want to evaluate. Go and Rust solving different problems and have very different ergonomics. D is most C-like.
- dathinab 6y agoI'm pretty sure that's not the case. Why I can't speak for him from what I have heard about him I don't think he is a fan of C++ either. So D wouldn't be his think either.
- MuffinFlavored 6y agoSTEVE, GET IN HERE!
- inshadows 6y agoThe innocent looking CLI thingy linked below turns into 68 MB binary when built with cargo build --release https://github.com/mozilla/application-services/blob/master/components/tabs/examples/tabs_sync.rs https://github.com/mozilla/application-services/blob/master/... I don't think Rust can replace C for CLI tools. It feels more like Java with these uber binaries.
- fgonzag 6y agoIsn't that statically compiled though? I haven't checked too much into Rust but I seem to recall it could be dynamically compiled. I would imagine any OS base tools would be dynamically compiled anyways. Though considering the lengths that package managers go to for dependency management, maybe static linking everything is not a bad idea after all, I don't mind a 10GB OS image on disk as long as it isn't actually wasting memory.
- inshadows 6y ago% ldd tabs_sync linux-vdso.so.1 (0x00007fffb06d0000) libdl.so.2 => /usr/lib/libdl.so.2 (0x00007fd523f96000) librt.so.1 => /usr/lib/librt.so.1 (0x00007fd523f8b000) libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007fd523f69000) libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007fd523f4f000) libc.so.6 => /usr/lib/libc.so.6 (0x00007fd523d88000) /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007fd52490a000) libm.so.6 => /usr/lib/libm.so.6 (0x00007fd523c43000) It still links to libc. It seems most of it is loads of Mozilla stuff. Oh, the nss lib is actually linked statically. Rust Evangelism Strike Force has struck me already. That was fast!
- gpm 6y agoldd just prints the things it dynamically links, which is basically just libc and related system interface libraries. You want to list then number of things it statically links. If you run cargo clean; cargo build, and check out target/debug/deps you should be able to get a list of all the statically linked rust libraries, which is a subset of all the statically linked libraries. Also, as other people mentioned, this is including debug information and so on. Strip it if you care about size. Rust is perfectly happy to make very small executables, you just have to ask it to.
- gfs 6y agoI don't know how significant a year is but this was written in 2019.
- dathinab 6y agoPartially, mainly points be addresses have gotten some but slow improvements. E.g. the part of rust but having a side is a think the rust community doesn't like to much either so there is long ongoing with to slowly and steadily get to a point where you can have a spec. And that had gotten a bit more traction this year I think. Also I think there are by now more alternate rust compiler projects, through no real alternatives and work in alternative non llvm backers. (Like there is the idea to have a cranelift backed allowing much faster but also much less optimized rust debug build.).
- blackrock 6y agoI would like C functions to have default parameter values, and named parameters. There are some tricks to achieve this, but they’re all rather cumbersome.
- Gibbon1 6y agoI'd like it if C had read arrays and range types like Ada.
- blackrock 6y agoDoesn’t Ada have bounds checking? This would be super useful, and prevent a large problem with buffer overflows. It would be nice to have some flag to turn it off, to increase the speed mode.
- thesuperbigfrog 6y ago>> Doesn’t Ada have bounds checking? Yes. Ada numeric types can be defined to only allow a specific range of values: Integer types: http://www.ada-auth.org/standards/12rm/html/RM-3-5-4.html http://www.ada-auth.org/standards/12rm/html/RM-3-5-4.html Floating-Point types: http://www.ada-auth.org/standards/12rm/html/RM-3-5-7.html http://www.ada-auth.org/standards/12rm/html/RM-3-5-7.html >> It would be nice to have some flag to turn it off, to increase the speed mode. Many Ada implementations have compile flags to turn off runtime bounds checking.
- Gibbon1 6y agoHaving real arrays would make both the compiler faster and array operations faster. range and mod types as in Ada would also squelch a bunch of C's shitastic undefined behavior bullshit. And your comment about just implementing it via a feature flag would be the way to go.
- ohazi 6y agoYou're not going to write microcontroller firmware in Go, but several people are doing just that in Rust, and it actually works quite well. Philosophy aside, in actual use Go is a better Java, not a better C. If your C program could have been a Java program, then go ahead and use Go. But lots of C and C++ programmers who consider Rust and decline to consider Go do so because the trade-offs that Go makes (garbage collection, error handling ergonomics, generics, etc.) really aren't that appealing. Not everybody is writing web servers for big-iron Google servers.
- dathinab 6y agoStill go had been designed with some philosophical overlap with C, just with a GC. And then massive concurrency was added. Anyway go is mostly good for cases where C or a very C like C++ where used but C want the best fit, like certain server applications. Ironically it's design makes it also pretty bad for many other server applications.
- valbaca 6y ago"Ironically it's design makes it also pretty bad for many other server applications." Can you elaborate? genuinely curious
- lostmsu 6y ago> Go is a better Java Maybe off topic, but I highly doubt Go is better than Java. Have not seen anyone convert to it from Java yet. Most come from Python.
- dathinab 6y agoBe aware that this article is by now over a year old. While I respect him a lot for a lot of the work he does some of the thinks in that article are IMHO just not right (and hadn't been a year ago either). E.g. yes cargo is somewhat mandatory but no rust doesn't refuses to play along. It's just that if you try to integrate rustc in the same way you would do so for a C/C++ compiler it wouldn't work because they way rust build thinks it's very different. So the best way to integrate rust into another build system is through cargo, which had been extended with such and other use cases in mind (emitting metadata etc.). Also in practice you often have similar problems for C/C++ projects which requires you to use that specific build system or port and maintain houndred of lines of <make/python/..> code. Worse the isn't a standard way to do thinks like running tests or seeing which features so exist.
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- Koshkin 6y agoIt’s not Rust’s fault. C is irreplaceable. Even C++, “a better C,” couldn’t. Nothing can.
- _bxg1 6y ago> Concurrency is generally a bad thing Okay, bud.
- xiphias2 6y agoRust doesn't try to be a C replacement. It's a great C++ replacement, for big performance-critical projects: Mozilla Firefox code was written in C++, not in C.