Hacker News new | ask | show | jobs
by sddfd 2515 days ago
This is great! Many dev hours are spend waiting for the compiler, every second counts!

The second order effects are even worse. After a minute, the programmer will start thinking about other things, running flow.

If compiles regularly take 5min, devs will leave their desks (and honestly, who can blame them for it).

4 comments

I just use `cargo watch -x test -d 5` to run all my tests after I pause modifying code for 5 seconds.

My editor (emacs) uses `cargo watch -x check -d 0.5` to run `cargo check` (which is blazing fast for incremental edits) to type check all the code and show "red squiggles" with the error messages inline.

So my interactive workflow with Rust is only edit-"type check"-edit-"type check" where "type check" takes often less than a second.

Asynchronously in the background, the whole test suite (or the part that makes sense for what I'm doing) is always being run. So if a test actually fails to run, I discover that a little bit later.

I don't know any language for which running all tests happens instantaneously. With Rust, if anything, I write less tests because there are many things I don't need to check (e.g. what happens on out-of-bounds accesses).

This is the best workflow I've ever had. In C++ there was no way to only run type checking, so one always had to run the full compilation and linking stages, where linking took a long time, and you could get template instantiation errors quite late, and well, linking errors. I don't think I've ever seen a Rust linking error. They probably do happen, but in C++ they happen relatively often (at least once per week).

> In C++ there was no way to only run type checking

gcc has -fsyntax-only. Despite the option name, this also includes type checking and template instantiation. AFAIK it reports all compiler errors, though it skips some warnings that are computed by the optimizer (e.g. -Wuninitialized).

Is there an easy way to tell CMake or Makefiles to use it ?

I never invoke clang or gcc directly. When using cargo, I use `cargo check` instead of `cargo build`. But in C or C++ depending on the project `make check` might not exist, or it might build all tests and run them, or do something else entirely like checking the formatting using clang-format.

> - CMake > - Easy

Pick one. I'm sure there is though.

It wouldn't be hard with make but then again I'm much more familiar with it than cmake.

So I manage to get it to work in the command line using `CXXFLAGS="$CXXFLAGS -fsyntax-check" cmake ... && make` !
One issue with that is that is, unless there is magic handling of the flag in cmake, it might still attempt (and fail) to run the linking stages. You might need custom targets jut for this.
Dump a compilation database with -CMAKE_EXPORT_COMPILE_COMMANDS=1 and wire up a script to call those commands but with the syntax only flag.
> In C++ there was no way to only run type checking

-fsyntax-check on GCC and IIRC clang as well.

If you use Emacs you can integrate it w/ flycheck.

I do use emacs! Can you integrate it with make and cmake via emacs somehow ?

Maybe doing `CXXFLAGS="$CXXFLAGS -fsyntax-check" CFLAGS="$CFLAGS -fsyntax-check" make ...` ?

You can easily get linking errors when using bindgen to link to C libraries (usually in the form of -sys crates). In fact, I once spent a fair bit of time trying to figure out how to link to FFmpeg (libav*) on Windows, without success.
> start thinking about other things, running flow.

I've found it a helpful practice as a programmer to be intentional about this.

With a little awareness, you can identify situations where it really would be best to busy-wait while something compiles. (If the wait is not all that long and switching tasks harms focus.)

And with a little mental discipline and practice, you can train your mind not to wander. You don't totally blank your mind out, but you also don't let unrelated thoughts distract you. Just continue to think about the same thing you were when the compile started. Don't shift gears mentally, just ease up on the mental gas pedal.

It's so easy to let anxiety or guilt about wasting 2 minutes lead you into giving up focus, which is more precious. It's a false economy, and thus doing something else with those 2 minutes is actually more of a temptation than a smart idea.

(Of course, it's better if the tools are just fast! But sometimes you can't have that.)

Reading this reminded me that I'm only here because I was waiting for a compilation & flashing to finish. I will not tell you how many minutes ago.
Incremental compiling has helped a lot here. Even if the first compilation takes awhile, the next one will be much swifter.

It's especially useful when only making minor changes to the code (which is pretty common).