Remix.run Logo
lelanthran 4 days ago

> C++ and C rely, heavily, on skill and discipline instead of automated checks to stay safe.

You can't sensibly talk about C and C++ as a single language. One is the most simple language there is, most of the rules to which can be held in the head of a single person while reading code.

The other is one of the most complex programming languages to ever have existed, in which even world-renowned experts in lose their facility for the language after a short break from it.

saghm 4 days ago | parent | next [-]

And yet, they both still suffer from the flaw that the parent comment cites. Describing a shared property doesn't imply a claim that they're the same language.

lelanthran 4 days ago | parent [-]

> And yet, they both still suffer from the flaw that the parent comment cites.

I dunno; the flaw is not really comparable, is it? The skill and discipline required to write C bug-free is an orders of magnitude less than the skill and discipline required to write C++.

Unless you read GGPs post to mean a flaw different to "skill and discipline required".

saghm 4 days ago | parent [-]

I'd argue that their point was that the required amount of skill and discipline of either is higher than it's worth at this point for new projects. The difference doesn't matter if even the lower of the two is too high.

estimator7292 4 days ago | parent | prev [-]

Have you written significant amounts of C or C++?

Most people don't write C, nor use the C compiler, even when writing C. You use C++ and the C++ compiler. For (nearly) all intents and purposes, C++ has subsumed and replaced C. Most of the time when someone says something is "written in C" it actually means it's C++ without the +± features. It's still C++ on the C++ compiler.

Actual uses of actual C are pretty esoteric and rare in the modern era. Everything else is varying degrees of C++.

QuiEgo 4 days ago | parent | next [-]

Sending out a strong disagree from the embedded systems world. C is king here.

(Broad, general, YMMV statement): The general C++ arc for an embedded developer looks like this:

1.) discover exceptions are way too expensive in embedded. So is RTTI.

2.) So you turn them off and get a gimped set of C++ with no STL.

3.) Then you just go back to C.

magnushiie 4 days ago | parent [-]

Skype was written without exception handling and RTTI, although using a lot of C++ features. You can write good C++ code without these dependencies. You don't use STL but with cautious use of hand-built classes you go far.

Today I wouldn't recommnend Skype built in any language except Rust. But the Skype founders Ahti Heinla, Jaan Tallinn and Priit Kasesalu found exactly the right balance of C and C++ for the time.

I also wrote a few lines of code in that dialect of C++ (no exceptions). And it didn't feel much different from modern C++ (exception are really fatal errors)

And regarding to embedded, the same codebase was embedded in literally all the ubiquitous TVs of the time, even DECT phones. I bet there are only a few (if any) application codebases of significant size to have been deployed at that scale.

QuiEgo 4 days ago | parent | next [-]

Sure, you absolutely can use a limited set of C++, and find value, and there are many big projects that have gone that route.

See Embedded C++ - https://en.wikipedia.org/wiki/Embedded_C%2B%2B

Apple's IO Kit (all kernel drivers on macOS/iphoneOS/ipadOS/watchOS) is a great example of what you're talking about. Billions of devices deployed with code built on this pattern.

That said, in the embedded world, when you get down to little 32-bit or 16-bit microcontrollers, not amd64 or aarm64 systems with lots of RAM, pure C is very prevelant. Many people don't find much value from classes when they are writing bare-metal code that primarily is twiddling bits in registers, and they also can't or don't want to pay the overhead for things like vtables when they are very RAM constrained (e.x. 64kbyte of RAM is not that uncommon in embedded).

So, I disagree with the idea that "actual uses of C are esoteric" from the post - it's very prevelant in the embedded space still. Just want people to think about it from another use case :).

The classic example of a big pure-C project at scale is the Linux kernel.

Ask Linus what he thinks of C++. His opinions are his own (EDIT: I actually like C++ a lot, please don't come at me with pitchforks! :)), I merely repost for entertainment value (from a while back):

https://lwn.net/Articles/249460/

Maybe a simpler example: go find a BSP (board support package) for the mirco of your choice. It's almost certain that all of the example code will be in C, not C++. They may or may not support building with g++, but C is the lingua franca of embedded devs.

4 days ago | parent [-]
[deleted]
4 days ago | parent | prev [-]
[deleted]
rramadass 4 days ago | parent | prev | next [-]

Right on the money!

Other then hardcore embedded guys and/or folks dealing with legacy C code, I and most folks i know almost always use C++ in various forms i.e. "C++ as a better C", "Object-Oriented C++ with no template shenanigans", "Generic programming in C++ with templates and no OO", "Template metaprogramming magic", "use any subset of C++ from C++98 to C++23" etc. And of course you can mix-and-match all of the above as needed.

C++'s multi-paradigm support is so versatile that i don't know why folks on HN keep moaning about its complexity; it is the price you pay for the power you get. It is the only language that i can program in for itty-bitty MCUs all the way to large complicated distributed systems on multiple servers plus i can span all of applications to systems to bare-metal programming.

unscaled 4 days ago | parent [-]

In practice, C++ is a language family more than a single programming language. Every C++ project I've worked on essentially had its own idiolect of C++.

rramadass 4 days ago | parent [-]

This is just a oft-repeated cliche and nothing more. Because C++ is a multi-paradigm language (with admittedly some less than ideal syntax/semantic choices) people overstate its complexity without much study/experience. Herd mentality than takes over and people start parroting and spreading the canard.

For the power and flexibility that C++ gives you, it is worth one's time to get familiar with and learn to use its complexity.

pod_krad 11 hours ago | parent [-]

>people overstate its complexity without much study/experience

The is no need in any experience to have ability to estimate C++ complexity. C++ specification is about 1500 pages.

lelanthran 4 days ago | parent | prev [-]

> Have you written significant amounts of C or C++?

Yes.

> Most of the time when someone says something is "written in C" it actually means it's C++ without the +± features.

Those "someone's" have not written a significant amount of C. Maybe they wrote a significant amount of C++.

The cognitive load when dealing with C++ code is in no way comparable to the cognitive load required when dealing with C code, outside of code-golfing exercises which is as unidiomatic as can be for both languages.