4 ms·
> Based on your comment, it would seem no one should use C/C++ Maybe, there are better options out there these days for parallel and concurrent programs. Paral
by ModernMech 5y ago
> Based on your comment, it would seem no one should use C/C++
Maybe, there are better options out there these days for parallel and concurrent programs. Parallel programming in C and C++ is extremely fraught for the very reasons the parent brings up. There are so many footguns, starting from the fact that the favorite debugging method of C programmers, printf(), is not even thread safe.
It’s so bad that Rust markets as a feature “fearless concurrency”, capitalizing on the recognition that the prevailing emotional state of a C or C++ dev writing concurrent or parallel programs is one of fear.
And the very thing that makes Rust concurrency fearless over C and C++ is that borrowing and mutability are explicitly tracked. As we enter a world where over a dozen CPU cores are the norm, we are learning what works and what doesn’t in writing programs for these machines, and integrating those learnings into new languages.
- nomel 5y ago> starting from the fact that the favorite debugging method of C programmers, printf() Most everyone I know uses a debugger. Maybe you're mostly exposed to beginner programmers?
- pjmlp 5y agoThere are couple of them that share this kind of opinions, https://lkml.org/lkml/2000/9/6/65 https://lkml.org/lkml/2000/9/6/65
- nomel 5y agoI sympathize with what he's saying, and I imagine he's correct, for his context, but some of us don't work on never-ending code and just want to write the best code we can, as quickly as possible, so we can move on to the next challenge. For those that are more pragmatic, and enjoy working on the hard problems the code is trying to solve rather than the hard problems of the code, using a debugger can be beneficial.
- pjmlp 5y agoThere are tons of ways to use debuggers, even in places that might seem one needs to contend themselves with printf debugging, what many miss is learning what is actually available. So you end up with legions of Linus hatting on debuggers and proud themselves of never having to use one, some kind of macho thing I guess.
- slaymaker1907 5y agoI prefer printf because it works pretty much anywhere, handles concurrency by default (as in you can see the interleavings, though the log call itself is locked), and allows me to have a custom tailored view of the state I want to see. The last point may not be obvious, but debuggers have tons of noise for complex programs. In practice I just want to see how my program state changes over time while a debugger shows the entire program state or a large subset of it. I think the future of debugging is going to be structured program state logging. Ideally we should be able to take our logs and partially reconstruct program state over time. For example, in addition to source location, we should save the lexical information for each variable logged so you can have interactivity with your logs and source code.
- zem 5y agoI've been programming for years and I still find printfs an extremely useful debugging technique. they let you debug an entire program in parallel, as opposed to the more focused single snapshot debugging you do with a debugger.
- pjmlp 5y agoOne detail that usually is left out of the fearless concurrency story is that it only works in-process across threads, it does very little to help in distributed concurrency across multiple processes accessing shared data, eventually written in various languages. Which in the age of micro-services is quite relevant as well. Definitely better than other languages, still doesn't prevent one to actually think about end-to-end overall system design.