Live data from Hacker News

It's time to halt starting any new projects in C/C++

twitter.com

341–350 of 929 posts

Re: It's time to halt starting any new projects in C/C++

#341
post #315

Earlier quoted context omitted.

Dereferencing NULL pointers: my code is structured such that every function parameter that can be NULL is marked so. And I check those possibly-NULL pointers. This could also be done with a macro: #define y_d(p) ((p) == NULL ? abort(), *p : *p) Otherwise, the compiler (clang, usually) warns me when a NULL pointer is passed in and I have asserts to catch them. Even before I had all of this infrastructure, deferencing…

Do you have a tool that enforces the use of all of these macros and stuff? How do you know that, for instance, you didn't forget something? Seems like one slip-up is all it would take.

This is where C fails against Rust. I have to use static analyzers to find such problems.

But I do use them, and I also use sanitizers against large and thorough test suites, with excessive fuzzing thrown in for good measure. And I mix all of that with crash-happy code littered with gobs of `assert()` calls that document as many of my assumptions as I can find.

Those help me find about all I can find.

But I'm still writing a language that is as safe as Rust that I will auto-translate my code into when it's done.

By the way, I'm not using Rust because I don't like it. That doesn't mean it's not good, but I really hate async/await, along with a few other Rust design decisions.

I'm kind of picky as a programmer.

Yes, C fails against Rust here, but that's why I put in the extra effort to bring it up to the same level regardless.

Re: It's time to halt starting any new projects in C/C++

#342

Earlier quoted context omitted.

Just cus they add a feature to a language doesnt mean u have to use it. Though it does seem very few programmers are smart enough to stick to the most basic features whenever possible.

C++ the "language culture" unfortunately has a lot of gatekeeping as well. The fact that the gatekeeping generally revolves around "replace feature from n-5 years with the newer feature in the latest 0x00x release" is a bit tiresome. Yes, I'm exaggerating, a bit. As for the Microsoft whomever-he-is: I agree in theory, I disagree in practice. If there are a lot of C++ devs writing important code, then let them continu…

> "replace feature from n-5 years with the newer feature in the latest 0x00x release"

Let me put a more pro-C++ spin on that sentiment.

C++ is a language that's under long-term development. It might sound weird, but only with C++20 Bjarne Stroustrup felt that his vision for the language was now mostly-realized - and he had worked on it since the 1980s. With other languages, there's a lot of clearing-of-the-desk and starting things anew, while C++ has opted for incremental changes with backwards compatibility to before it existed (i.e. C).

But, looking back, we get the sentiment you describe. Which, rephrased, sounds like this:

"Remember that annoying and ugly hack you had to use so far to get [complex thing] to work? Well, that finally got fixed. Now there's a shiny new language feature / standard library construct which does that more nicely. But your existing code will also work."

Re: It's time to halt starting any new projects in C/C++

#343

Earlier quoted context omitted.

I don't want to sound too girle or fanboyish but there is no other way to say it so I'll say it (hopefully he won't read this)- Mark Russinovich transcends titles and if he's said something about technology, it's probably 99.999% true. Also, RITF, I love Rust but remember zig exists so chill I also want to say one thing-- sometimes it's not so easy to just decide to write a project and say okay let me write this in R…

RITF? Research Institute of Tropical Forestry? Rat Intestinal Trefoil Factor?

RITF: Rust Is The F____

Re: It's time to halt starting any new projects in C/C++

#344
post #229
post #148

Earlier quoted context omitted.

Are new devs less likely to screw things up in Rust? Probably. Is a modern Rust codebase easier to onboard with than a 40 year old monstrosity of a Microsoft C++ codebase? You bet! Are more people excited about learning Rust? Probably. Is rust much faster to learn than C++? Call me a skeptic. I've written Rust professionally and would rather write Rust than C++. That said, almost every concept you need to understand…

> That said, almost every concept you need to understand C++ is also needed to understand Rust I agree that many basic C++ concepts are also present in Rust, but C++ is more than just its basic concepts: it's a huge set of features on top of those that interact with each other in complicated ways. Like how constructors aren't functions but something very special. If you just want to be a beginner C++ dev who works al…

Rust's "feature surface area" reaches or exceeds that of C++ through procedural macros, which surfaces the entire Rust AST to the developer. Major Rust crates like serde use this feature, and when it goes wrong the errors are actively misleading. I've personaly been bitten by this, it's incredibly frustrating to debug. https://serde.rs/derive.html#troubleshooting

Re: It's time to halt starting any new projects in C/C++

#345
post #31

The C/C++ people hate it when you call it C/C++.

That's a fairly recent thing that some people do as a kind of virtue signaling. The "C/C++ Users Journal" was a very popular publication and no one took issue with its name. Nor do people take issue with Dr. Dobbs which has a "C/C++" section with articles from highly influential members of the C/C++ community. C++ is a complex language, so people invent ways to show how dedicated they are to it, and nowadays that mea…

> That's a fairly recent thing that some people do as a kind of virtue signaling.

It was a pretty common correction the comp.lang.c newsgroup in the 1990s.

"Hey you dolt, there is no C/C++; they are different languages."

"Oh yeah? Well look at how when I run cl.exe, it says Microsoft C/C++ compiler!"

"Haha, C/C++ is actually undefined behavior: C++ is modified and independently accessed in the same expression ..."

Re: It's time to halt starting any new projects in C/C++

#346

Earlier quoted context omitted.

I don't want to sound too girle or fanboyish but there is no other way to say it so I'll say it (hopefully he won't read this)- Mark Russinovich transcends titles and if he's said something about technology, it's probably 99.999% true. Also, RITF, I love Rust but remember zig exists so chill I also want to say one thing-- sometimes it's not so easy to just decide to write a project and say okay let me write this in R…

RITF? Research Institute of Tropical Forestry? Rat Intestinal Trefoil Factor?

Hmm, seems like a NSFW concept: https://www.urbandictionary.com/define.php?term=RITF

Re: It's time to halt starting any new projects in C/C++

#347
post #228
post #211

I tried Rust about five years ago and I had trouble expressing cyclic data structures because there is no clear "owner" in a cyclic data structure. The "safe" solution recommended by the rustaceans was to use integers as references to the data in a vec or hashmap. I was rather put off by this: Instead of juggling pointers I was juggling integers. It made the code harder to debug and find logic errors. At least when I…

The borrow checker has become smarter, but not at handling cyclic data structures. The problem you're describing still exists, though I'd say the advice isn't quite right. Generally the better advice is to use a graph library, or something like slotmap [1] if you're rolling your own, than to use a Vec or HashMap. That's superior to a vec/hashmap for a few reasons. It handles keeping indicies stable/writing your own i…

What is the advantage of a slotmap style approach vs references? It seems a bit manual and error prone, and the errors risk being silent references to wrong objects that may result in security vulnerabilities or data corruption.

Re: It's time to halt starting any new projects in C/C++

#348

Unless he means that Rust should be used on projects where the Rust compiler is available for all relevant platforms and C and C++ can be used otherwise, I disagree. In fact, until LLVM is replaced, C++ will probably be the language of choice for new languages. Even `rustc` requires a C++ bootstrap for that purpose. There are also other important C++ and C libraries that will continue to mean C and C++ may be better…

"Oh, and it's possible to make C as good as Rust", do you have some concrete advice documented somewhere? Thanks!

Write a full unit and functional test suite and run them with asan, tsan, msan and maybe valgrind. This has caught all the memory bugs before getting to production in my experience.

You need the test suite to verify that your code does what you think it does anyways, the sanitizers are just a nice bonus to verify that it also has the safety you think it does.

Re: It's time to halt starting any new projects in C/C++

#349
I get that it makes sense at his level, but my impression is that mistakes in the business logic are both more common and more financially painful for the company than the memory safety issues that Rust solves when compared to C++.

Unsafe binary? Run it in docker.

Crashes? Run two and monit.

RAM leak? Restart with cron.

Now I'm not saying that these are good solutions, but they are good enough so that plenty of companies get away just fine with running buggy c++ software in production. So in my opinion, the biggest improvements come from better abstractions and good libraries. And c++ still has the lead there.

Re: It's time to halt starting any new projects in C/C++

#350
post #211

I tried Rust about five years ago and I had trouble expressing cyclic data structures because there is no clear "owner" in a cyclic data structure. The "safe" solution recommended by the rustaceans was to use integers as references to the data in a vec or hashmap. I was rather put off by this: Instead of juggling pointers I was juggling integers. It made the code harder to debug and find logic errors. At least when I…

Unsafe is literally made for that. For cases when your wants can only be checked by your brain saying "I did the logic and it's all good". Ten lines of unsafe does not mean your program will blow up. If anything, it's here to encourage you to just be much more careful here.
Post reply on HN