2 ms·
For interest's sake, why didn't you go for Rust? It's really in the wind these days and people also claim it can work on embedded.
by sgt 2y ago
For interest's sake, why didn't you go for Rust? It's really in the wind these days and people also claim it can work on embedded.
- jvanderbot 2y agoC is trivially upstream of everything. Rust is slightly less upstream of everything, in that you have to essentially go through C to do it. C is also very small and easy to hold in your head, with minimal required dependencies, aside from standard system libraries. Rust typically pulls dozens of dependencies for even small libraries. These are just tradeoffs. If I were going to build a small library to do something with libcurl, I might do C first then Rust for expanding if required. Same for specialized processing like rasters or computational geometry or even linear programming - all those are C already, and rarely do you find a perfect Rust crate that exposes everything you want. And unsafe rust is definitely harder than just writing C. It often is easier to write it mostly in C then expose app/higher API level functions to Rust, rather than do the business logic in Rust.
- hollerith 2y agoYou can write Rust code with no dependencies (not even Rust's standard library) and coders do so regularly when writing code for microcontrollers. That is one of the primary advantages that distinguishes C and Rust from most languages (which tend to depend completely on a library to do automatic memory management for example). It is advantageous not only on constrained systems like microcontrollers, but also when interfacing with code written in one of the languages that has a hard dependency on a runtime library to manage memory.
- jvanderbot 2y agoOf course this is true with minor effort. I'm not doubting rusts benefits, I write rust full time for a reason. Just answering why sometimes C is first.
- flohofwoe 2y agoBut now you're (almost) back to basically carving out your personal language subset, which is also one of the biggest problems in the C++ ecosystem (it is possible to write 'sane C++', but everybody's sane subset looks slightly different, which massively fragments the library ecosystem and leads to endless frustrating and pointless discussions whether a library should make use of this or that language or stdlib feature).
- pjmlp 2y agoWell does one write ISO C, GCC C, clang C, AIX C, xyz C? It is the same issue as well.
- atiedebee 2y agoNot really, most C programs (especially libraries) are written in C89 or C99. GNU-C and all other dialects are generally reserved for when you write an application that won't be interfaced with through code.
- pjmlp 2y agoI guess we don't look at the same kind of examples, specially in the enterprise world.
- pjmlp 2y ago> C is also very small and easy to hold in your head Mostly true during K&R C days, without taking into consideration C compiler dialects outside UNIX V6. Already during 16 bit home computer days it was already flexible enough with compiler extensions all over the place, that most folks would fail a pub quiz on C. Even more so with C23 as current.
- flohofwoe 2y agoI tried Rust a couple of times since 2018 or so, but it's just not my thing. I do maintain Rust bindings for my libraries on the side though, so I'm not completely unaware of Rust's development, but try to follow it from the sidelines watching for interesting new things - unfortunately Rust's development looks like it's fast-tracking C++ of becoming a kitchen-sink language but in much shorter time - and that's on top of the vast 'semantic surface' that Rust needs for being able to build a static memory safety proof. I think this is one area that can't easily be reduced unless the compiler gets a lot smarter (or at least is allowed to peek into called function bodies - which probably wouldn't help the already bad compile times though). Basically, Rust feels a lot like C++ to me, "just" with static memory safety added on top (and tbf, most historical footguns fixed, but the 'better C' languages did that too). Both writing (modern) C++ and Rust feels more like type-system puzzle solving than programming, this might be exactly what attracts some people (and would also be very attractive to a more junior me), but personally: when I write or maintain code, the programming language should 'disappear' into the background, and both Rust and C++ don't have that quality, they always want your attention which distracts from the actual problems to solve. Zig, Odin and even C all have that quality of quietly humming along in the background, you don't think about language features when programming, the code just kinda flows from your brain into the keyboard. Having said that, I would probably pick Rust for isolated problems and where memory safety is absolutely mission critical (like a sandbox that needs to run untrusted code) - but then use an unsafe language for the code that runs in that sandbox (because what's the point of a sandbox anyway if it can't safely isolate unsafe code).
- nvarsj 2y agoGreat description of the problems of C++/Rust - that puzzle like property attracts a lot of younger engineers and creates a lot of conference talks that hyper focus on the language instead of how it can solve real problems. Scala suffers the same thing in my experience.
- com2kid 2y agoZig is fun. Rust is a battle. If I have to choose between 10x safer than C and enjoyable to write, or 12x safer than C and a PITA, I'm choosing Zig.