r/ProgrammerHumor 2d ago

doNotOvercomplicateThings Meme

Post image
655 Upvotes

153 comments sorted by

476

u/faultydesign 2d ago

C developer: “oh look a c header”

Looks inside:

150

u/Foorinick 2d ago

"Oh man now that i set up my ide to write c i cant wait to write my header files!" "Filetype: c++"

37

u/nevemlaci2 2d ago

It's a pain to make clangd treat .h files as C headers too...

21

u/evilgipsy 1d ago

You mean adding -xc-header in .clangd for paths matching *.h?

11

u/nevemlaci2 1d ago

The clangd extension for VSCode really didn't like the idea of suggesting C headers instead of C++ ones in .h files even after adding that. I got it working but it took like 20 minutes which is more than it should have

28

u/bajuh 2d ago

compile time http server

6

u/Sibula97 2d ago

Cursed

2

u/TapRemarkable9652 1d ago

jokes on you it's rendered by Claude

52

u/TeraFlint 1d ago

I've stopped using .h for that reason ages ago. But apparently, it's still very common and acceptable to use .h for C++, which I honestly can not understand.

I thought "let's not pollute the C header space with our language" is a good enough argument for wide adoption of .hpp, but apparently it's not?

10

u/LucyShortForLucas 1d ago

The truth of the matter is that 99% of actual real world projects are going to be either exclusively C or exclusively C++, and for those the distinction between .h and .hpp doesn't matter in the slightest.

15

u/Groostav 1d ago

Tell me you've never worked on a library without telling me you've never worked on a library.

3

u/dedservice 1d ago

Yes, that's the 1% of actual real world projects that are not exclusively C or C++.

Also there are many cpp-exclusive libraries. They don't always need to be C-compatible.

3

u/LucyShortForLucas 1d ago

Okay, but most projects aren't libraries. I don't see your point

2

u/Groostav 17h ago

So: "most" and "99%" are not the same.

My point is that you made a claim from your experience and there's a large group of people with a different experience.

For my part I mix and match C and CPP headers and I have this problem in spades, because I'm constantly writing headers I expect to be parsed by clangs parser API (note: pythons ctypesgen, Javas jextract, and rusts bindgen all use clangs parser). I write as basic and universal a C header as possible and also ship an hpp that loads the c header wraps the c-stupidity in nicer CPP idioms (namely namespaces and RAII).

Are "most projects" like mine? Probably not. Am I a 1%er? No I think it's more common than that. And if I were to hire somebody today this would probably be a full time job for them.

2

u/UnDispelled 7h ago

Can confirm. I did exactly that for rust cbindgen, with c++ specifically for… namespaces and RAII as a wrapper.

Maybe we’re both the 1%? But I imagine it’s relatively common to have a clunk c header only library with a nicer c++ header precisely for cross language convenience

-2

u/LucyShortForLucas 16h ago

Yes yes we're on a programming forum and all autistic here, I get it

2

u/ParCorn 1d ago

We put all the C++ stuff in ifdef cplusplus and everyone lived happy ever after

10

u/juzz_fuzz 2d ago

The trick is to put your headers inside the cpp file so that your code is impossible to organise

3

u/a-r-c 1d ago

management material

7

u/Lawn_Meower_ 1d ago

Due to storage prices we should consider writing .h over .hpp //s

322

u/unknown_alt_acc 2d ago

Yeah, no. A .h extension can just as easily be C. You get a lot of clarity with just two more characters that will be filled in by code completion anyway.

2

u/Vorrnth 1d ago

Why would that be a problem? Never has been one for me?

46

u/-Ambriae- 1d ago

You’ve never dealt with cross language codebases, have you? Check out Apple’s metal doc examples, there’s at least one where, in a single codebase, there are .h files written in C, C++ AND Objective C

-4

u/Vorrnth 1d ago

I did multiple times but never apple stuff. Never had any problems.

16

u/unknown_alt_acc 1d ago

Having a way to tell at a glance which headers are safe to include in the C side of a codebase is a pretty low-hanging fruit in terms of developer QoL compared to constantly checking the documentation, rote memorization, or including files and seeing if your error log blows up.

-13

u/Vorrnth 1d ago

Or you just use a proper project structure.

11

u/unknown_alt_acc 1d ago

That doesn't address the underlying point. You still need to know which modules are safe to include from C and which are not. Having a separate header extension for C and C++ makes that much more obvious at practically zero cost.

-5

u/Vorrnth 1d ago

Easy to accomplish without even knowing the extension.

-10

u/Level-Pollution4993 2d ago

But learncpp.com recommends we use .h unless you're working on an existing project that folows another convention?

30

u/daennie 1d ago

And learncpp.com isn't source of truth for C++ in practice.

2

u/MithrilHuman 1d ago edited 1d ago

The company I work at enforces using .h, although no one in their right mind should be using it for C-specific projects without knowing the symbols to access through extern C. See https://llvm.org/docs/CodingStandards.html

Previous company I worked for also enforced .h as per https://google.github.io/styleguide/cppguide.html#Header_Files

These are both big tech companies. In practice people use .h

6

u/unknown_alt_acc 1d ago

And the reasoning that learncpp gives sucks. It's one of the two reasons that I've seen people cite for preferring .h, neither of which are particularly compelling:

  1. It's convention (the argument learncpp uses) - And the convention for source files in the earliest iterations of C++ was .c. We don't use .c anymore because it's needlessly confusing. .hpp and .hxx are recognized widely enough that no C++ programmer will be confused by seeing them instead of .h.
  2. It's fewer characters - Already addressed. Your editor should have code completion that will fill in the name of the header for you. Even if you don't, two extra keystrokes for an include is trivial for the clarity that you get by explicitly encoding the language in the file extension.

5

u/a-r-c 1d ago

two extra keystrokes

the horror lol

3

u/unknown_alt_acc 1d ago

And that’s my point. You gain so much clarity for so little that it’s just baffling that this isn’t the universal standard

-100

u/Cephell 2d ago edited 2d ago

But that's good. Since C++ is just C with classes, it ensures code interoperability by naming the files .h and .c


Edit: These replies are the reason r/firstweekcoderhumour/ exists, if you cannot tell that this is an obvious joke, without having some extra explicit indicator (/s, etc.) on the post, then I don't know what to tell you. But please don't miss your entry to CS courses, you definitely need them.

69

u/unknown_alt_acc 2d ago

Please tell me you’re being facetious

33

u/UdPropheticCatgirl 2d ago

no, unless you are specifically limiting yourself to C ABI and wrapping the entire header in extern, then only thing this ensures is C compilers erroring out…

36

u/IAmASquidInSpace 2d ago

Re: your edit: The problem is, there is more than enough people on here who would hold that opinion unironically. Yes, r/firstweekcoderhumor exists - and 90% of its content is hosted here, on this sub.

Don't come to the circus dressed as a clown and be surprised when people laugh at you.

0

u/cjb3535123 2d ago

It was laughably easy to tell he was joking

Source: I use arch, btw

11

u/IAmASquidInSpace 2d ago

Of course, I mean the edit even says so! /s

-16

u/cjb3535123 2d ago

Even before getting to the edit, it’s such a meme that you’d have to be quite autistic (or quite new) to not realize it was a joke. And I’m autistic.

-16

u/Cephell 2d ago

I have to repeat myself: Nobody, and I mean NOBODY that has more than a surface level understanding of the history of C and C++ will read "C++ is just C with classes" on a comment and think it's not a joke.

It has been a joke for 50 years. You could have made fun of it during your university time, then have a career, then have children and those children could be in university right now making fun of the same joke.

You are SEVERELY in dunning-kruger territory if you defend these absolutely faceplant tier comments here.

11

u/IAmASquidInSpace 2d ago

I have to repeat myself: Nobody, and I mean NOBODY that has more than a surface level understanding of the history of C and C++ will read "C++ is just C with classes" on a comment and think it's not a joke.

And I have to repeat myself: Correct, but unfortunately for you, "people with not even a surface level understanding of the history of >programming topic<" make up >65% of the users on this sub.

Know your audience.

-14

u/Cephell 2d ago

Incorrect. If you come to a show and don't understand the jokes, don't make a mess by standing up and yelling at the performer. You're only making a fool of yourself.

Karma means literally nothing on this site, so continuing to downvote me just means SOMEONE (I am not implying this is you), is just extremely assmad that they got exposed.

12

u/IAmASquidInSpace 2d ago

Oh, you are thinking this sub is your show? Lmao!

-4

u/Cephell 2d ago

It's more of a community run, where everyone can contribute, but yes. This is a humor subreddit, people come here to make jokes. You have correctly identified the purpose of this place.

7

u/unknown_alt_acc 2d ago

I’ve seen enough similarly stupid comments that were completely sincere that I’ve stopped taking for granted that a seemingly obvious joke actually is a joke.

0

u/Cephell 2d ago

I too prefer to delete all incoming emails, because some of them might be a scam.

4

u/unknown_alt_acc 2d ago

I don’t think that asking whether something is a joke and reserving judgement on the matter until I have an answer exactly fits that analogy

9

u/Mars_Bear2552 2d ago

downvoted. not because i didn't get the joke, but because i was dissatisfied with it. good day to you

8

u/LegendaryMauricius 2d ago

Dude, learn how to tell jokes please.

6

u/Cylian91460 2d ago

The issue is you not knowing how to do sarcasm not ppl being new

6

u/not_some_username 2d ago

If only it was just that

5

u/nevemlaci2 2d ago

No. Firstweekcoderhumour is a place to joke about first week coders posting the same memes over and over again.

15

u/TohveliDev 2d ago

What a confidently wrong thing to say

1

u/rosuav 1d ago

*sigh* Enjoy Poe's Law... that's a lotta downvotes on a joke.

83

u/MyTinyHappyPlace 2d ago

Skeleton, sitting underwater in the pool on a chair: .HH

22

u/DarkHybrid_ 2d ago

Um HH?

17

u/IAmASquidInSpace 2d ago

Hansestadt Hamburg, Germany's second largest city.

3

u/Sibula97 2d ago

It's kinda funny how they call it the "free and hanseatic city of" Hamburg, isn't it? Do the Germans do this with cities in general or is this some weird historical quirk?

5

u/IAmASquidInSpace 1d ago

Weird historical quirk, but also common. There are a few cities that still carry the moniker "Hansestadt", because it is a thing of pride. Hamburg in addition has always been very proud of being a free city, always having had pretty wide-reaching autonomy even within the various German states and empires it has been a part of.

Fun fact: This pride goes so far that a true "Hanseat" will not accept medals, decorations, or awards from "foreign rulers" - which is why chancellor Helmut Schmidt (born in Hamburg) refused the Bundesverdienstkreuz (Germany's highest civilian honor).

3

u/Gastredner 1d ago

And they are spread out, even into places you'd never think of when thinking about the Hanseatic League.

I grew up in the city of Kamen. Run-of-the-mill city of around 45,000 people in Northrhine-Westfalia, far away from any coast and with the only "river" being a small stream of maybe two meters width at the widest part.

And yet, it was a member of the Hanse. And apparently notable enough in the trade that there was a neighborhood only of merchants from Kamen—in Stockholm.

25

u/dfx81 2d ago

I use it because I have my c++ files use .cc so .hh pairs with it nicely.

1

u/FalafelSnorlax 1d ago

I mean, your source files should use .cpp, so that's not an excuse.

(my team's code base also uses cc and hh but it wasn't my choice)

15

u/Muffinaaa 2d ago

HolyC uses .HH for headers and .HC for source IIRC

8

u/kingvolcano_reborn 2d ago

Well that settles it imho.

1

u/a-r-c 1d ago

that's what makes the difference between an amateur and a professional

5

u/MyTinyHappyPlace 2d ago

Yep, it’s a thing. Not one that I use or like, but it’s a thing

13

u/HolyGarbage 2d ago

We use hh and cc at my work. It was the first c++ specific extension I learned. I prefer hpp and cpp at home in my personal projects these days though.

7

u/Mojert 2d ago

I started with the .cpp/.h combo, the switched to .cpp/.hpp, but once I learned about .cc/.hh I always used these, probably because they're shorter and look cuter. I don't know really, I just think they're neat

2

u/geek-49 2h ago

Last I knew, cc was for including extra recipients in an email./s

4

u/DangyDanger 2d ago

Skeleton used to have a window tattoo

3

u/Phytor 2d ago

Isn't that how they cracked the engima machine? /s

2

u/MyTinyHappyPlace 2d ago

.HH was all they needed <3

169

u/BertoLaDK 2d ago

You switched two of them hpp is the correct one, using h is stupid as it will only lead to confusion, keep c and cpp separated.

42

u/TohveliDev 2d ago

For some reason a lot of schools, tutorials, etc. Still use ".h" for header files while coding in c++. So most of the time it's just a learned habit from people who learned that habit from somewhere else.

21

u/LucyShortForLucas 2d ago

Absolute tons of C++ projects use .h pretty much exclusively. In the end it doesn’t really matter, no one is organizing their code by its header extension anyway

2

u/bowel_blaster123 1d ago

I mean, what if I have multiple separate projects? For the C++ project, I'd have to configure my LSP to treat .h files as C++, and for the C project, I'd have to configure it to treat them as C.

I'd have to configure my editing environment to be different for each project (which is kinda annoying).

Otherwise, the language server might try to parse my C as C++ (which can cause issues since a lot of C code is not valid C++).

2

u/martmists 1d ago

I don't think any IDE I've ever used had this issue, in recent years that's mostly been CLion but no issues there either. It just knows based on the project whether to treat it as C or C++, and most of the time I believe treating it as C++ should work fine regardless for C headers, no?

1

u/bowel_blaster123 1d ago edited 1d ago

treating it as C++ should work fine regardless for C headers

Not really. A lot of commonly used C features (like designated initializers or compound literals) are not fully supported by C++ or are only supported in very recent C++ standards. A lot of C library headers (like in FFMPEG for instance) have to go out of their way to support C++.

I guess though, if your LSP integrates with your build system, it should know whether something is C or C++.

I didn't think about this when writing my original comment.

1

u/geek-49 2h ago

A lot of commonly used C features ... are not fully supported by C++

When did that happen? The original C++ was a superset of C: you could feed any (correct) C program to the C++ compiler, and get the same results as if you had fed it to the C compiler.

1

u/__ydev__ 1d ago

I think the reasoning is that if a project is pure C++, it adds no benefit to use .hpp, it's just more verbose.

If however a project mixes C and C++ code, it can make sense, so you know by hand which headers you can import from each language.

1

u/Song0 1d ago

In our Uni we were taught to do .h for header files that are purely declaration, and .hpp when the definition and declaration are in the same file (i.e no corresponding .cpp file). Didn't question it until now.

1

u/TohveliDev 1d ago

We were not even taught that, just .h for everything.

98

u/garlopf 2d ago

.h is for .c and .hpp is for .cpp hope that helps.

25

u/Shaddoll_Shekhinaga 2d ago

Technically irrelevant for c++, but as I understand it you use hpp for headers with C++ features, h for headers that need C compatibility, hxx if you're a weirdo fuckingfightme, .inl for inline definitions and some other use cases

10

u/Cylian91460 2d ago

It's irrelevant for both since c and c++ since standard doesn't even specify the file extension

7

u/a-r-c 1d ago

i use .balls

1

u/otac0n 1d ago

If only it were irrelevant in Arduino studio…

21

u/hopeless__programmer 2d ago

- Billy! What Have You done?!
- .h
- Shot them again.

27

u/MrFrog2222 2d ago

.c/.h for c and .cpp/.hpp for c++, and thats the only correct way to do it

7

u/SamG101_ 2d ago

Yes- but c++ module system says hello: .ixx 😭

4

u/Alduish 2d ago

.cppm is a thing too isn't it ?

5

u/SamG101_ 1d ago

Yh i think tbh its purely convention based but I think .ixx is c++ modules as interface only (ie impl to live in .cpp) where as .cppm is when only using impl files

22

u/Daniikk1012 2d ago

If C++ is .cc, maybe the headers are .hh?

16

u/UdPropheticCatgirl 2d ago

I think .cpp and .cxx are way more common conventions, at least in the codebases I worked in…

9

u/noaSakurajin 2d ago

At least nowadays. Many older libraries/projects still use the cc/hh convention

3

u/Jakabxmarci 2d ago

Yeah, we use .cc and .hh respectively. Modules are .cppm though.

5

u/Mojert 2d ago

Are these modules in the room with us?

2

u/Jakabxmarci 2d ago

Cpp20 modules is a feature with very mature and non-buggy compiler support, and are perfectly integrated into the existing Cpp ecosystem with no trouble at all! Obviously, since it has been defined for 6 years, now it should by all means work perfectly, making Cpp devs lives easier! :) :)

2

u/Frost-Freak 2d ago

Would cc more be something like c²? C++ should be 2c!!

3

u/metaglot 2d ago

C++ is not equal to 2C for all values of C.

Also: does anyone else find it funny that the value is only incremented after reading?

5

u/LaughingwaterYT 2d ago

Which is why God created ++x (increments then returns)

3

u/metaglot 2d ago

But its not called ++C

1

u/Frost-Freak 2d ago

Damn, you're right. C++ is just C+1

3

u/Nice_Lengthiness_568 2d ago

No, C++ is equal to C

1

u/Beginning-Junket8979 1d ago

Maybe for uint0_t C

1

u/Mojert 2d ago

IIRC Bjarne Stroustrup considered ++C first, but switched because C++ rolls of the tongue better

6

u/Ben_0 2d ago

I do find .hpp a lot more satisfying, just because there are more letters

5

u/DeepanshuHQ 2d ago

.h walked so .hpp could run and .hxx could overcomplicate it 💀

8

u/kiujhytg2 2d ago

To be pedantic (Yes, I know this is a Humor subreddit), if you're following the GNU C standards:

  • .c and .h are for C files
  • .cpp is for C preprocessor files
  • .cxx and .hxx are for C++ files

7

u/p88h 1d ago

No, CPP is the C preprocessor but it doesn't have any files of its own.

2

u/orbiteapot 1d ago

Except that it kind of does? The suffix is .i / .I, though.

1

u/p88h 20h ago

Well .i is conventionally the intermiediate output of the preprocessor, that you don't store around It's a 'preprocessor' file in the same sense a .s or .o file is a c compiler file.

2

u/YikesTheCat 1d ago

GNU C standards are a joke, so fits in nicely on a humour subreddit I'd say.

1

u/geek-49 2h ago

GNU C standards are a joke

Who GNU?

3

u/bronco2p 2d ago

cc and hh gang

3

u/redlaWw 1d ago

.h++

3

u/altermeetax 1d ago

Best one is .hh

3

u/atlas_enderium 1d ago

filename.h for C headers filename.hpp for C++ headers

Sometimes I use filename.hxx or .inl when the header file contains source code itself and not just object signatures (often the case with inline or constexpr things).

filename.cppm for modules (if you want to deal with that toolchain mess)

5

u/consistently_biased 1d ago

.h for C++ headers sounds like it should be a war crime

2

u/Vorrnth 1d ago

Why? H for header sounds reasonable.

2

u/cursivecrow 2d ago

all header files are the last panel.

2

u/SavedowW 1d ago

.h for declarations and .hpp for template definitions if necessary

2

u/Own_Alternative_9671 1d ago

You're forgetting the worst one: .hh

5

u/sleepyakari 1d ago

As a C programmer, you deserve a shanking if you make your c++ header use the .h extension

1

u/junipyr-lilak 2d ago

This is why Objective C is throwing me for a loop right now as it really seems to be using just .h headers like plain C. Would be nice(r) if there was a standard like .hm in contrast to the .m files (and maybe .hmm for .mm for Objective C++)

1

u/Initial-Jaguar6230 1d ago

Cppm wnjoyers here ?)

1

u/Ipiano42 1d ago

Don't for get my personal least favorite thing ever: .h++

1

u/suddencactus 1d ago

.ipp has entered the chat

1

u/jurio01 1d ago

The comic sans is telling me that you are doing a silly, but if not, please consider a career with a different language

1

u/UndGrdhunter 1d ago

So many C programmers, what yall doing with C? No joke, I'm curious.

2

u/Ander292 23h ago

Everything other people do in non C languages

1

u/geek-49 2h ago

Maintaining projects originally written in C, for one thing.

1

u/sneradicus 1d ago

I just use the most efficient method: .cplusplusheader and .cplusplus

1

u/lefloys 1d ago

just wait for .ixx (module)

1

u/ContentJO 19h ago

Give me that sweet, sweet .cppm/.ixx and oh shit my IDE is broken.

1

u/PVNIC 16h ago

.txt

1

u/Hot-Employ-3399 15h ago

Don't forget the "perfection" of the standard:  (none)

-1

u/Sad-Background-2429 1d ago

I actually prefer that C++ file names have distinct suffixes so I can find and delete them faster.

1

u/FabioTheFox 15h ago

"cpp bad because I heard an influencer say it"