Stop Saying C/C++
brycevandegrift.xyz
brycevandegrift.xyz
> He said, "Yes." I said, "Are you a Christian or a Jew?" He said, "A Christian." I said, "Me, too! Protestant or Catholic?" He said, "Protestant." I said, "Me, too! What franchise?" He said, "Baptist." I said, "Me, too! Northern Baptist or Southern Baptist?" He said, "Northern Baptist." I said, "Me, too! Northern Conservative Baptist or Northern Liberal Baptist?"
> He said, "Northern Conservative Baptist." I said, "Me, too! Northern Conservative Baptist Great Lakes Region, or Northern Conservative Baptist Eastern Region?" He said, "Northern Conservative Baptist Great Lakes Region." I said, "Me, too!"
> Northern Conservative†Baptist Great Lakes Region Council of 1879, or Northern Conservative Baptist Great Lakes Region Council of 1912?" He said, "Northern Conservative Baptist Great Lakes Region Council of 1912." I said, "Die, heretic!" And I pushed him over.
In context of The Famous Article, if Judaism = ALGOL, C = Catholism and C++ = Protestantism, then (at least some) Baptists have a Pascal attitude, never having bought off on Rome enough to protest against it.
Due to the above, stuff like `{ Foo * c = a + b; }` may have a completely different interpretation in C++ than in C.
Few people would write C++ as if it were C. They would then rather write C instead.
A C++ compiler happens to include a C compiler, and allows to easily mix C++ and C code. This is just a convenience; the Zig compiler also includes a C compiler and allows to easily mix in C code, but nobody would mistake Zig for C.
Saying "C/C++" is like saying "car/aircraft", just because an F-150 and a Cessna 182 happen to include a piston engine and a seat behind it.
I would entertain a job that involved C development but I would be very hesitant to to entertain one for C++
I'd certainly prefer to hire someone with both tools available, to use where appropriate, not a religious ideologue obstinately refusing to consider anything that's unpure.
Why in the world would you use K&R syntax to demonstrate the differences between C and C++? Some of the most readable C code I've looked at has to be Sean Barett's single header files. And he sure doesn't use K&R syntax, and for good reason. Why not show something much simpler? Like the fact that you don't need to typedef a struct to use it without adding the structure keyword to the type like you do in C?
> Lots of Suckless users and developers only use C and POSIX shell in their programs. Cat-v endorses C and C-like languages, but despises C++. Even Linus Torvalds, the creator Linux and Git, won’t touch C++. Heck, even I love C but I can’t stand programming in C++
Ok man, you can gatekeep all you want. You know what's funny? Games are probably one of the quintessential examples of software that requires the performance of C or C++. And you know what the most sold game of all time is? Oh yea, Minecraft, written in Java. I'm sure that makes you shudder. And you know what? I'm glad Notch didn't listen to a bunch of gatekeepers and wrote it in a language he knew and could use and blessed the world with this amazing game.
Also, some people just don't hate themselves. They're not too hard core to realize that C has some very real flaws, but may still appreciate the simplicity of C. Those programmers may program in C++ in a style very close to C, but with the additional benefit of generic programming for type safe containers instead of a bunch of hideous macro magic that's bound to bite you in the ass very quickly. And you know what? There's nothing wrong with that either.
The funny thing is, I agree with the title of this article, but the whole tone is just gross. I'm so sick of gatekeepers ruining programming for newcomers and old timers alike. In the true spirit of being a hacker, quit being so anal and let people just code and kindly correct them if they spread a misnomer like the idea that C and C++ are 100% equivalent.
It also looks like it's been deprecated since C89 and the use of the style has also been discouraged since then according to this article[0].
> At the time, they felt they could not remove the K&R “old-style” definitions. It had not been deprecated long enough, and the new syntax had not been around for long enough (it hadn’t been around at all, in fact). So, they rolled it into C89 deprecated, and explicitly discouraged its use for some 33+ years.
[0]: https://thephd.dev/ever-closer-c23-improvements#at-the-time-...
Now what's the most distributed game? I'm pretty sure Microsoft Solitaire was on more machines than Minecraft. ;)
I do agree that they're very different, and should not be conflated (and I'm one of those programmers who will happily code C but despises coding in C++), but there is definitely a clear connection between the two, just as there is between C and Objective C.
Also, that maximumCount example in C++ is unreadable not because it's C++ code, but because the author has deliberately tried to be extra clever in writing it.
There are contexts where "C/C++" makes sense, sure something like "program Foo is written in C/C++" usually doesn't make much sense (though it can make sense if it is written in both languages - i.e. using both C and C++ modules) but something like "program Foo is a C/C++ code generator" (think something like a generator for header files for example) in that the code it generates can be compiler as either C or C++. After all, unlike Rust, Go and Kotlin mentioned in the article, C and C++ do share a sizable common subset (heavily biased towards the C side of course). This is why C header files can often used as-is in C++ or with the minor modification based on the __cplusplus macro.
Language is meant to be parsed by humans, not computers and humans can take context into account (and with the recent developments in AI even computers can do that too :-P).
>
> C and C++
> C, C++
> C++ with C
> Etc.
>
> NOT C/C++
>
> Only if you’re using C together with C++ would it be acceptable to say C/C++.
oh ffs, stop it with the pedantry.
How long of a blog post because "c/c++" isn't "c and c++"? It's neurotic.
C code filled with macros being replaced by C++ classes and template instantiations makes code just on an aesthetic level look very different. RAII vs "getNewX/destroyX".
Not judging either flavor, but I think it's rare to see a file of "C/++" code and not immediately grok what you're looking at.
Admittedly, the author did a phenomenally poor job at highlighting the differences that people should care about. Nobody cares about casting malloc or K&R syntax. People do care about compilation time, binary size, strong type systems, name mangling, debugging, complexity, error messages, embedding etc.
Technical discussion aside, I'm saddened by the dismissive nature of the comments. Even if you're not at a point where you can internalize why someone else is asking to stop saying "C/C++", the unempathetic nature of the comments is discouraging.
Not the author but I sense that going down that road there is risk of derailing into which lang is best.
Not necessarily, and even if this is true, I still do not care about what someone else’s passing opinion might be.
And in fact, if C and C++ were as this article claims they are, then they wouldn’t need to propose new special terminology for putting them together. You don’t say either “C/Java” or “C, Java” because they’re both sufficiently distinct.
I also said 'or'.
There is legal C that is legal C++ but has different observable behaviour
And if you're "writing C in C++" then you're not really using C++ as it was intended, might as well just write C and use a C compiler.
Well it was, once upon a time; as https://en.wikipedia.org/wiki/C%2B%2B puts it,
> Initially, Stroustrup's "C with Classes" added features to the C compiler, Cpre, including classes, derived classes, strong typing, inlining and default arguments.[22]
...but that's not really true anymore. Certainly, C++ has classes, and there is a decent-sized overlap between them such that you can write code that compiles (correctly, even) in both, but each has plenty of things that isn't legal in the other, and C++ has a lot of features that C doesn't have, to the point that I suspect writing in the subset (or intersection, rather) of C and C++ results in what modern C++ devs would consider non-ergonomic, non-idiomatic code.
All jokes aside, this is just too nitpicky for me. I'm not sure if the author is personally upset that C and C++ get lumped together because they don't like C++ or something, or if they have some other gripe with the confusion, but I think it's very obvious why C and C++ get grouped together: they're... Similar and related.
The argument is "No; they're not similar! They're actually very different" and I simply reject this. Yes, they are not the same. Idiomatic C code and idiomatic C++ code are quite different. They are not compatible.
Yet, they share many concepts that basically only languages derived from C do. They aren't compatible, but mostly because they diverged over time, and it's easy to port C code to work in C++ (typically it can be done mechanically, unless you count some newer features.) Hell, is there a C++ compiler that doesn't support (some form of) C?
And while idiomatic C code and idiomatic C++ code may differ, they're not oceans apart. What really sets C++ code apart in my mind is the concepts of RAII and operator overloading. The existence of classes with inheritance may push you to code a certain way, but I think a lot of modern codebases don't even wind up using inheritance the way you might traditionally. For example, it has become common to only use inheritance for pure virtual base classes, using inheritance to implement a sort of interface composition system instead. This is also not so different from a pattern you would often see in C software where you pass a table of function pointers to implement polymorphic behaviors... In fact, it's basically the same thing.
C and C++ may feel far apart to die hard fans of only C, but it should signal something that most of the rest of the world doesn't really see it. C and C++ are definitely different, but fundamentally closer than C and C++ are to many other languages, including languages with C in the name like C#, and arguably "modern" successors like D and Go, too. (Not to mention Rust.)
I am certain that this notion does upset people because they feel it gives C a bad name, but people are always going to have misconceptions and misplaced stigma about your favorite things sometimes. Policing the way people speak is not an answer, not necessarily because there's no truth to the point that "C/C++" for example is misleading, but because there's enough truth to the point that "C/C++" makes sense to make it difficult to convince people to stop naturally associating the two.
I'm sympathetic to the overall view here (not sure I agree, just that I understand it), but this a terrible argument. People say that you can write C code in a C++ program because it doesn't need FFI. You just write in the shared subset that is legal C and legal C++, and then - and this is kind of the point - you feed it into either compiler and it works.
Granted, I don't think this piece of writing makes the argument as well as it could.
The post answers itself right off the top. They're close enough that finding someone with experience in either is potentially qualified to be considered for a role.
For someone who specializes in only C or C++, they're very different. In the context of programming languages on the whole, experience in one often means a lot of context to using the other.
If you have a problem with "C/C++", I'd even have a problem with saying C++ since usages can vary so widely. I learned K&R C, then some MSVC++ with MFC/ActiveX/COM, some OS/2 SOM/IDL C++, then more ANSI C and later C++. But now the modern C++ I sometimes see is quite different. No one uses all new features but if they did, it seems like a different language. We still call it all C++. And to me C is still an improper subset.
Edit: I also sometimes write F#/OCaml, is that wrong? Depends on the context.
No truer words for me. And yes, the article makes a lot of sense to me. If I see C/C++, I ignore the ad.
edit: nevermind, it's undefined behavior in both, though likely equals either 1 or 2 in C... (2 on my system) :)
</irredeemable recalcitrant>
C and C++ each have their own language idioms, just like other programming languages have their own.
There are usecases where you want to reuse code written in one language from within another. The evolution of C++ took a pragmatic look at this and provided mechanisms for that. If you are not using C++ or don't have that use case, that is fine. But language choice depends on a lot of other factors other than just pedantry.
I'm still maintaining C++ compact in my pure C projects, just because the C++ compiler is soo much better finding opportunities and errors. C analysis is just too loose.
When we say that someone knows c/c++ we mean that they know how to manage memory.
still C and C++ have a totally different approach to program design: A C project of non trivial size will have lots of insane tricks with macros and callback functions, whereas C++ has entirely different methods of abstraction.
I think that's a very significant difference.
Also C++ has this std::unique_ptr<> thing that helps a lot with preventing memory leaks. And C++ has stl, so you won't have to write your own list/array/map abstractions.
After several years of production programming... you will see the languages are not mutually exclusive:
And I never seen that you can mix Go/Java/... and C Syntax/standard lib in one file.
What a BS...
I think this is a rant / a perspective everyone needs to hear once. It might be old hat and boring to people who've been programming for decades, but so long as we keep creating new programmers, we'll unfortunately need to keep reiterating this lesson.
But for "I need something that compiles to native to frob a couple syscalls", being idiomatic matters less than remembering what compiler needs to be installed.
Because JS only has the word "java" in the name because that's the name people were going to get tricked into thinking it was a serious thing over. Which is why the "real" language hassn't been called JavaScript for two decades now (but no one's going to use its real name, because ecmascript? really? do I need a cream for that?)
Baiting pedants is fun, basically. They always go off and 95% of everybody does an eye-roll. Then I point out that there is a very significant subset of C that is also a subset of C++ and it's actually a very good and useful subset that we mostly always program in. And we could call that, very large, subset of C, C/C++. HAHAHAHAHA!
\o/
Ohhh, c'mon.
Writing idiomatic code in C vs C++ however is very different.
People are using C/C++, this is a thing.
In reality a C++ app is highly likely to use a C API somewhere.
- Basically all Linux apis
- the official Redis library
- etc
int class;C and C++ evolved over time but they stayed close enough that you can relatively easily compile C code with a C++ compiler.
The few incompatibilities are historical artefacts that would probably disappear at some point if the future, for the better.
C and C++ are kind of two flavours of the same language, with different styles and paradigms.
Referring to C/C++ is talking about both styles, and yes they can be mixed and that is perfectly fine.