4 ms·
I appreciate the intent, C has become its own thing with its own set of conventions, and people still writing "C/C++" often reveal that they don't have a clue a
by codeflo 4y ago
I appreciate the intent, C has become its own thing with its own set of conventions, and people still writing "C/C++" often reveal that they don't have a clue about either.
I think many C programmers might disagree with large parts of this, however. Some things that caught my eye that might be controversial:
> Wrap your structs in a typedef
The only reason to do this that's mentioned is "annoyance", which I think is a weak reason if you have the kind of problem for which you're considering to use C. The author already mentions that it has a weird interaction with forward declarations. It's my understanding that many C codebases don't do this, simply to be more explicit about what's a struct and what's not, and to avoid typedef explosion.
> the POSIX standard reserves the ‘_t’ postfix for its own typenames to prevent collisions with user types – make of that what you will ;)
IMO, that's not something to casually dismiss with a smiley. If it's reserved, don't do it.
> Typedef only creates a weak type alias not a proper new type (it’s really not much better than a preprocessor define), meaning there’s no warning when assigning to a different type from the same base type
The point is somewhat valid, but the author seems a bit confused about terminology here. It's not "a different type from the same base type", instead, it's a different name for the same type. The comparison with the preprocessor is unwarranted.
> Be (somewhat) afraid of pointers
Why? The following rant about RAII doesn't really give that many clues. Handles can have a performance penalty vs pointers -- or be a performance benefit, this really depends on the details.
Also, this is where it might have been helpful to go into different conventions about allocations, whether the caller or callee should allocate, etc.
- rightbyte 4y ago> people still writing "C/C++" often reveal that they don't have a clue about either. How about "Java/Groovy" or "C#/VB"? C++ and C are related enought to write that I think. Especially since it is common to mix the languages in projects.
- nextaccountic 4y agoI think you're right. For example, I think Android apps written in Java/Kotlin are better than apps written in web technologies
- tialaramex 4y agoI think the things that particularly gets people angry are: - When someone says "C/C++ Programmer" but they actually mean either a C programmer, or a C++ programmer, and hey, it's all the same right ? This is obviously related to the general cluelessness of recruiters. The 19 year old wide boy recruiting people for your bank will try to bring in an experienced embedded C programmer to interview for a post on your 5MLOC C++ line of business application, and they also aren't clear on the difference between Mystic Meg (an Astrologer) and Edwin Hubble (an Astronomer). It's also infuriating when people who supposedly know either language describe themselves this way. If you actually know C or C++ fairly well, you should know they're different in important ways and it's unlikely you actually know both equally well. - When a project/app/whatever is described as written in "C/C++" but almost always this means either, "It's actually C++ but a few files are technically not using any features exclusive to C++ so I guess a C programmer could understand them" (that's just C++) or "It's actually C, but we did compile it with g++ and that worked". If we saw Firefox referred to routinely as being "C/Javascript/C++/Rust/Python/Assembler" then I don't think you'd see as big a reaction to C/C++ but people will act as though "obviously" somehow the C and C++ in Firefox are basically interchangeable, but the Python and Javascript are not.
- pjmlp 4y agoPeople bashing about C/C++ don't have any clue about English grammar rules.
- lvass 4y agoElaborate.
- colejohnson66 4y agoI think they’re referencing how English grammar isn’t consistent, but at least C and C++ have a defined grammar (from the spec). Therefore, people bashing C and C++ should look in the mirror?
- pjmlp 4y agoNo, actually referring to use of / in English grammar.
- pjmlp 4y agoAny reference to an English grammar will easily explain that / is an abbreviation for or. "The Proper Use of the Forward Slash in English" https://eslgrammar.org/forward-slash https://eslgrammar.org/forward-slash Thus C/C++ as in C or C++. On top of revealing lack of grammar knowledge, it also reveals lack of understanding of ISO papers, documentation from all companies with seat at ISO, their job boards, and major publications like the now gone "The C/C++ Users Journal".
- flohofwoe 4y ago>> ...POSIX and _t... > IMO, that's not something to casually dismiss with a smiley. If it's reserved, don't do it. It only matters when your own type names collide with any of the POSIX type names, and it's not like POSIX is changing much nowadays. A collision with 'recent' C standard additions is much more likely, and those are not predictable anyway (such as alignas() or unreachable()).
- flohofwoe 4y ago> Also, this is where it might have been helpful to go into different conventions about allocations, whether the caller or callee should allocate, etc. There's another blog post about memory management which might have aged a bit better (at least it's less controversial heh): https://floooh.github.io/2018/06/17/handles-vs-pointers.html https://floooh.github.io/2018/06/17/handles-vs-pointers.html
- WalterBright 4y ago> It's not "a different type from the same base type", instead, it's a different name for the same type. This is why after much consideration, D uses `alias` instead of `typedef`. `alias` works for other things, too, like creating an alias for a symbol: alias sqrt = math.std.sqrt; x = sqrt(y); or when you're sick of Java style names: alias eggs = CookAndEatEggsForBreakfast; eggs(); Of course, in C you'd use a macro for this. But C macros do not respect scoping, so using them is akin to using a table saw without a face shield.
- Gibbon1 4y agoI feel like 'alias' and 'copy' would be rather easy to add to C. alias bar = foo; // bar is an alias of foo copy baz = foo; // baz is copy of foo Alas we have the small problem of the do nothing standards committee.