68 points

Why does your header file contain code?

permalink
report
reply
33 points

It’s not the case with this meme, but in C++ template definitions have to be defined in the headers if they’re not full template specializations

permalink
report
parent
reply
-8 points

Oh for fuck sake. I thought the full on retardation hadn’t spread to c.

permalink
report
parent
reply
-4 points

Gonna go with… whoosh

permalink
report
parent
reply
43 points

The stone-age called, they want their languages that need header files back!

(I use Rust btw.)

permalink
report
reply
9 points
Deleted by creator
permalink
report
parent
reply
5 points

Did they add modules to the standard yet?

permalink
report
parent
reply
7 points
Deleted by creator
permalink
report
parent
reply
2 points

I know that header files have some pretty horrible issues with templates and cyclic dependencies and so on, but from an organisational perspective I really like them. If I have to implement some complicated algorithm I could easily have a thousand likes + of Code, but the header still quite nicely shows the general structure in one or two screens. Whenever I do classes in python I start wishing for headers at like 300 lines, simply because I loose track of all the functions I already made.

Maybe I’m just not a good python programmer tho.

permalink
report
parent
reply
3 points

I’d say at 1000 lines it usually makes sense to extract some parts into other files. But sure, I guess most obscurities have positive aspects. On the other hand, nothing is stopping you from writing a separate file with only function signatures next to your python scripts. It’s just not required, because why would it ;)

permalink
report
parent
reply
42 points
*

Why are you putting the implementation in the .h file? You’re supposed to declare in the header and implement in the .cpp files. The meme is reversed

permalink
report
reply
45 points

If C++/C were real languages for real programming they’d enforce this in the compiler.

No sane language designer would say “it is imperative that you do not implement your class in its header file” then write a compiler designer to say “oh you implemented your code in the header file? lol lmao that rocks”

They have played you all for fools.

permalink
report
parent
reply
18 points

I actually like how much freedom C++ gives you. As long as it is fed valid code, it does not give a fuck about how you choose to structure your project

permalink
report
parent
reply
2 points

That freedom becomes misery on the instant you have to start maintain the code from some other free spirit, whose style is totally different from yours.

permalink
report
parent
reply
6 points

not saying it’s good design, I ditched C++ long ago. at least the C++20 modules API is gonna fix this, right guys?

permalink
report
parent
reply
4 points

Header files aren’t part of the C++ language at all.

Also mandatory “C++/C is not a language”

permalink
report
parent
reply
Deleted by creator
permalink
report
parent
reply
-4 points

If C++/C were real languages for real programming they’d enforce unreadability in the compiler.

No sane language designer would say “It is imperative that you write the most unreadable code possible” then write a compiler that says “oh your code doesn’t triple dereference pointers? lol lmao that rocks”

They have played you all for fools.

permalink
report
parent
reply
12 points
*

There is an issue with templated code where the implementation does have to be in the header as well, though that is not the case here. C++20 introduced modules which I guess were meant to sort out this mess, but it has been a rocky road getting them to be supported by compilers.

permalink
report
parent
reply
-3 points

The reason is that header files are pretty much copy/pasted into your c files when you include them. so the code in them keeps getting recompiled for every c file, which drastically increases overall build times. If you only declare in the header and have one c file implementing the functions you compile them only once.

permalink
report
parent
reply
11 points

AI reply? That’s the point they’re trying to make. The implementation shouldn’t be in the header file, but it is. Look at the image.

permalink
report
parent
reply
-2 points

pretty sure the meme is about how the implementation looks ugly but using the implementation looks good because all the code is abstracted away. if it was like you said then why would they compare the code to the main.cpp

permalink
report
parent
reply
4 points
*

Yeah that’s why you’re supposed to use header guards… If you don’t and include your header in multiple places your program straight up won’t compile.

permalink
report
parent
reply
-3 points

drastically increases overall build times

oh wow. from 0ms all the way up to 0ms. That’s almost 1000 times faster wow.

permalink
report
parent
reply
3 points

truly spoken like someone who has never worked on a large C/C++ project

permalink
report
parent
reply
36 points

Looks like we’ve got a Java programmer here taking C++ for a spin.

permalink
report
reply
5 points

Yep, first thing that comes to mind is that header only classes need to use inline functions.

permalink
report
parent
reply
5 points
*

Member functions that are defined within a class definition are implicitly inline

permalink
report
parent
reply
3 points

Ah I see now that I mixed it up with classless functions in a header.

permalink
report
parent
reply
4 points

I haven’t codes anything in C++ for such a long time, I completely forgot how to.

permalink
report
reply
3 points

It’s horrible, I did pure C for years but now I have to code in C++11 or worst like C++17

permalink
report
parent
reply

Programmer Humor

!programmerhumor@lemmy.ml

Create post

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.

Community stats

  • 3.6K

    Monthly active users

  • 1.5K

    Posts

  • 35K

    Comments