39 points

I really wish more projects would use .hpp to differentiate from C headers. It’s really annoying to have a single header extension blend across two incompatible languages.

permalink
report
reply
19 points

I did this in a project and someone later came and changed them all to .h, because that was “the convention” and because “any C is valid C++”. Obviously neither of those things is true and I am constantly befuddled by people’s use of the word convention to mean “something some people do”. It didn’t seem worth the argument though.

permalink
report
parent
reply
14 points

…so that leads to another annoyance of mine. The insistence that there aren’t two languages but indeed one named C/C++. Obviously I’m being a bit sarcastic but people blur the lines HEAVILY and it drives me crazy. Most of the C code I’ve written is not compatible with C++…at least not without a lot of type casting at a bare minimum. Or a compiler flag to disable that. Never mind the other differences. And then there’s the restrict keyword, and the ABI problems if the C library you’re using doesn’t extern C in the headers…etc etc… -_-

permalink
report
parent
reply
4 points
*

Yeah, I use that all the time. I think I use it in a different way though. I have projects with C, C++ and other languages. The C and C++ get compiled and linked together, and so there are some considerations for those files that don’t apply to anything else. So I mean C files and C++ files, but not as if they were the same language.

permalink
report
parent
reply
1 point

reminder that .H can be used as a c++ header extension , along with .C for source files

permalink
report
parent
reply
1 point

Yep which IMO is ugly but I’d way prefer that over everyone using .h

permalink
report
parent
reply
1 point

honestly I use .hh/.cc which is quite nice IMO . you can also use .hpp/.cpp but I don’t like it personally

permalink
report
parent
reply
-3 points

C++ is a superset of C.

permalink
report
parent
reply
3 points
*

It’s actually not. Objective-C is a superset of C. C++ is not. It’s MOSTLY compatible…but it’s not a superset. See the restrict keyword, or the need for casting to and from void*, or the inability to name variables new or delete, or class, or this. I can’t count how many C projects I have which use this as a variable name that WILL NOT compile as C++…or the need for extern C to call C ABI code…in no way is it a superset

EDIT: lol, you can downvote me if you want but I think you need to lookup what a superset is

permalink
report
parent
reply
2 points

hpp is a superset of h

permalink
report
parent
reply
22 points

I don’t code in C++ (although I’m somewhat familiar with the syntax). My understanding is the header files should only contain prototypes / signatures, not actual implementations. But that doesn’t seem to be the case here. Have I misunderstood, or is that part of the joke?

permalink
report
reply
18 points

I’m not fully sure what the intent of the joke is, but note that yes, it’s true that a header typically just has the prototype. However, tons of more advanced libraries are “header-only”. Everything is in a single header originally, in development, or it’s a collection of headers (that optionally gets “amalgamated” as a single header). This is sometimes done intentionally to simplify integration of the library (“just copy this files to your repo, or add it as a submodule”), but sometimes it’s entirely necessary because the code is just template code that needs to be in a header.

C++ 20 adds modules, and the situation is a bit more involved, but I’m not confident enough of elaborating on this. :) Compile times are much better, but it’s something that the build system and the compilers needs to support.

permalink
report
parent
reply
3 points

Thanks. I didn’t know about these advanced libraries, and had not heard of C++ modules either. Appreciate the explanation.

permalink
report
parent
reply
5 points
*

Not a C++ developer, I prefer C. You are right in general however my understanding is that classes which are generic using templates must be fully implemented in header files because of how templates are implemented. That being said this code doesn’t appear to use templates so I’m not entirely sure I get it either?

permalink
report
parent
reply
2 points

I guess that’s the joke, and I think we’re all confused because it’s wrong.

permalink
report
parent
reply
1 point

Templates can now be defined somewhere else. It’s a small improvement that no one uses.

permalink
report
parent
reply
3 points

Well, it’s even just horrid code, because they’re reading user input in some random associated function, so I think, it’s safe to say that this is supposed to be horrid code.

permalink
report
parent
reply
1 point
*
Deleted by creator
permalink
report
parent
reply
10 points

Gotta love the

short loop = 0; // loop counter

and then just:

short amt;

What the hell is “amt” supposed to abbreviate?

permalink
report
reply
8 points

“amount” maybe?

permalink
report
parent
reply
5 points

Ew.

I mean, I was gonna respond with that, no matter what it might mean, but that’s such an unnecessary abbreviation.

permalink
report
parent
reply
7 points

There are not even templates there to justify it.

permalink
report
reply

I decide to learn C++ and suddenly everything and everyone mentions C++… Is that a sign?

permalink
report
reply
7 points

That you should turn and run like hell? Probably lol…

permalink
report
parent
reply

Well i don’t really have a choice as i want to code some stuff for my smartwatch (pine time) and also wanted to take a look at the code of the hyprland window manager (wich is written in C++ afaik)

permalink
report
parent
reply
2 points

Ah…well fair enough. I personally prefer plain C but I know nothing about the pine time or what languages are available and even then Hypr and Hyprland are C++ so you are trapped there…sway ftw lol. Also my pedantic side dictates I must say this even though it’s irrelevant…but technically Hyprland is a Wayland compositor and while they do manage windows a window manager is an X term…

permalink
report
parent
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 6.1K

    Monthly active users

  • 988

    Posts

  • 38K

    Comments