News for hackers. Stuff that matters.
Re:C meeting is over. C23 added: by bruce343434 on Saturday February 19, 2022 @05:04AM (#30395855)
I'm going for C, because I am experienced with C and despite it being more tedious, with having to do everything yourself, I stick with it because the compile times, and in fact the compile process, are so much faster and simpler. I really enjoy the direct feedback I can get. I considered C++ but that too had terrible compile times. Ideally a debug build should simply not take longer than 100ms for a codebase that isn't even 5KLoc, and only C seems to be able to offer that experience.
Re:C meeting is over. C23 added: by gefhfffh on Saturday February 19, 2022 @05:21AM (#30395954)
I get that the compile process is faster, but simpler?

In my experience, the compile process usually consists of "cargo build"

A advantage of Rust is that usually you spend way less time debugging, because the compiler prevents many mistakes from compiling in the first place.

Re:C meeting is over. C23 added: by bruce343434 on Saturday February 19, 2022 @06:07AM (#30396184)
I have an IDE with clang-lint and I find that it can spot pretty much every mistake. It can even detect some lifetime issues. Other than that my programming style is very much pass-by-value, trust the compiler to inline it, so the typical memory safety issues are simply not relevant to me.
Re:C meeting is over. C23 added: by pornel on Saturday February 19, 2022 @06:31AM (#30396305)
Pass-by-value and let LLVM clean it up is also the idiomatic Rust way. rust-analyzer is pretty good for IDE integration, and it will catch way more than clang-lint (global lifetime analysis with guaranteed correctness, not just best-affort local, and thread safety/data races).

Regarding compile times, Rust has a different approach. Instead of a fast cycle of run and see if it broke, it's more of following compiler nags until the program is correct and runs on the first try. Incremental (cached) compile times aren't too bad these days.

Re:C meeting is over. C23 added: by gefhfffh on Saturday February 19, 2022 @06:41AM (#30396357)
Before I tried Rust (I got sick of it and the slow progress of Herb Sutter's research), I have used CLion with clang-tidy and had plenty of memory issues going undetected.

Needless to say I didn't restrict myself to pass-by-value (compatible -> structs with ptrs are problematic as well) style, which seems quite restrictive

Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @09:36AM (#30397409)
With current ISO C++ velocity and the stance to keep doing language evolution in person meetings, I don't think Herb's proposals will ever come to be, and even if they do, it won't matter when they most likely can only make it post-ISO C++26 with best efforts.
Re:C meeting is over. C23 added: by CyberRabbi on Saturday February 19, 2022 @02:20PM (#30399691)
I’m going for C because programming language choice is a matter of personal preference in essence and Rust annoys me.
Re:C meeting is over. C23 added: by sgt on Saturday February 19, 2022 @03:26PM (#30400203)
How does it annoy you? Development velocity, creativity hinderance?
Re:C meeting is over. C23 added: by CyberRabbi on Saturday February 19, 2022 @06:24PM (#30401534)
Visually it’s annoying. It’s like the comic sans of programming languages.
Re:C meeting is over. C23 added: by sgt on Sunday February 20, 2022 @12:53AM (#30403558)
I used to code Perl in the late 90s. To me it doesn't look /that/ bad.
Re:C meeting is over. C23 added: by CyberRabbi on Sunday February 20, 2022 @05:18AM (#30404665)
If rust is comic sans then Perl is wingdings, so yes, it could be worse.
Re:C meeting is over. C23 added: by sgt on Sunday February 20, 2022 @06:36AM (#30404963)
Hilarious
Re:C meeting is over. C23 added: by dureuill on Saturday February 19, 2022 @06:00AM (#30396147)
You could get productive in Rust in 3 months max, and then the productivity gains would quickly outweigh the initial investment
Re:C meeting is over. C23 added: by donkarma on Saturday February 19, 2022 @06:22AM (#30396262)
Rust code takes longer to write than C code
Re:C meeting is over. C23 added: by dureuill on Saturday February 19, 2022 @06:38AM (#30396342)
My experience is mainly with C++, but from my own evaluation I'm x2 to x3 more productive overall in Rust than in C++. The reasons are a simpler build system that makes using the ecosystem faster, more expressive type system (iterators with combinators, sum types), the safety part that allows to not accidentally introduce UB and to not waste time with static and runtime analysis, shortening debug and review time. This compounds over time to give a better maintenance time.

I don't have a similar evaluation for C <-> Rust, but I suspect the result would be even more skewed in Rust's favor: sure, you might be writing individual lines faster in C, but the lack of iterators, generics, traits and RAII, and the relative difficulty to use dependencies means that you will waste a lot of time reinventing the wheel, often suboptimally.

Re:C meeting is over. C23 added: by pornel on Saturday February 19, 2022 @06:52AM (#30396423)
It does for a novice. But once you learn Rust, it's actually quite productive. Rust has proper collections, strings, iterators, automatic (but not GC) memory management, error propagation, etc. This eliminates a lot of busywork, and makes Rust "denser", so you write less code, but get more done.
Re:C meeting is over. C23 added: by hyperman1 on Saturday February 19, 2022 @09:14AM (#30397255)
No, the greenfield coding phase of Rust will always take longer than the same code in C: Rust will require you to think things through, while C by default accepts any morass of half-defined code.

The eventual rust code+debug+maintain speed will be higher than the equivalent C speed, for the same reason.

This means that rust is slower for vanity projects that won't be used in practice, or for low quality products with an attitude a la hack it- ship it - hide for customers - start next mess. The scary part: this is actually an existing corner of our market.

Re:C meeting is over. C23 added: by pornel on Saturday February 19, 2022 @08:36PM (#30402379)
I know where you're coming from. I've felt the same when I was novice in Rust, and could not imagine how people get anything done when 10 lines of code have 10 borrow checker issues to deal with. But this obstacle completely goes away once you understand ownership and Rust idioms, instead of trying to make rustc accept C-style code.

I have many years of experience in both, and I can confidently say that for experienced programmers Rust is both quicker than C to get something useful working, and to get projects polished and production-ready.

Rust has a useful standard library (compared to C). You have hashmaps, btrees, or vectors with lots of helper methods all available in less than it takes to hand-roll a linked list.

Rust has lots of high-level crates that you can leverage. You need to fetch some JSON? It's a few lines of code to get it into a native struct, type-checked for you. You can have it running in less than it takes to craft a Makefile.

Rust is also productive for robust code. You don't fiddle with malloc, so the whole `goto cleanup` code is gone, and you don't spend any time chasing memory corruption, leaks, or unexpected NULLs. And these are often static guarantees, not something to fuzz out of a stanitizer.

If you need code to be multi-threaded, it can be as easy and high-level as OpenMP, but you get a compile-time guarantee of no data races, even in 3rd party code you use. Some errors pointed out by the Rust compiler have saved me what could have been weeks of heisenbug debugging.

It's normal that you move slower when writing an unfamiliar language, and Rust certainly has a steep learning curve. But once you learn it, Rust feels closer to high-level scripting languages than C.

Re:C meeting is over. C23 added: by drran on Saturday February 19, 2022 @06:47AM (#30396386)
Total time of «coding + debugging» (development time) is shorter for safe Rust, because Rust eliminates few classes of errors. Unsafe Rust and C are same, but Rust have better abstractions (match operator, Rust enum's, typed macros, etc.)
Re:C meeting is over. C23 added: by flyinglizard on Saturday February 19, 2022 @05:45AM (#30396068)
Why does it matter if compile time is 100ms or 300ms? At even a second, that’s going to be so negligible in the context of code-compile-debug work. Especially if something like a flash download is involved.
Re:C meeting is over. C23 added: by flohofwoe on Saturday February 19, 2022 @07:49AM (#30396751)
The compilation time difference between C and Rust for nontrivial projects is much bigger than 3x.
Re:C meeting is over. C23 added: by truffdog on Saturday February 19, 2022 @04:48PM (#30400849)
Are there features you can ban in your style guide to prevent serious compile time problems?
Re:C meeting is over. C23 added: by OJFord on Saturday February 19, 2022 @06:40AM (#30396351)
Are your rust builds really that fast? Wth am I doing wrong! I'd love to measure it in seconds.
Re:C meeting is over. C23 added: by jamincan on Saturday February 19, 2022 @07:20AM (#30396584)
It's slow for me, but I'm not working on a very powerful machine.

That said, cargo check is fast, and my general experience with Rust is that it generally works once it compiles. People getting into more advanced features might have different experiences.

Re:C meeting is over. C23 added: by bruce343434 on Saturday February 19, 2022 @06:09AM (#30396192)
0. it is a noticeable delay and impinges my momentum

1. A flash download is not involved

2. I hardly debug. I seem to be in a minority here, but my linter really does catch pretty much everything. I don't blindly write code, I always ponder my approach first.

So basically, the compile times pull me out of the flow.

Re:C meeting is over. C23 added: by zh3 on Saturday February 19, 2022 @06:38AM (#30396337)
Very much with you on this one. Even with 50k+ LoC a 'make clean;make' takes less than a second (with help from ccache and a RAM disk). It effectively gets the compiler out of the way and keeps the thought processes continuous.

One trick I like is to have a 2nd terminal watching the file(s) I'm editing, triggering a make/run on each save; building and running is then a single keypress away:-

  while [ 1 ]; do
  inotifywait -e move_self foo.c
  cc foo.c -o foo && ./foo # or 'make && ./foo'
  done