230
True Story (lemmy.world)
you are viewing a single comment's thread
view the rest of the comments
[-] Lauchmelder@feddit.de 41 points 2 years ago* (last edited 2 years ago)

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

[-] merthyr1831@lemmy.world 44 points 2 years ago

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.

[-] SubArcticTundra@lemmy.ml 18 points 2 years ago

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

[-] tyo_ukko@sopuli.xyz 2 points 2 years ago

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.

[-] DraughtGlobe@feddit.nl 2 points 2 years ago

Or the free spirit was actually you yourself but from three months ago

[-] Lauchmelder@feddit.de 6 points 2 years ago

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

[-] brisk@aussie.zone 4 points 2 years ago

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

Also mandatory "C++/C is not a language"

[-] stingpie@lemmy.world -4 points 2 years ago

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.

[-] tunetardis@lemmy.ca 12 points 2 years ago* (last edited 2 years ago)

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.

[-] Lauchmelder@feddit.de -3 points 2 years ago

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.

[-] victorz@lemmy.world 11 points 2 years ago

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.

[-] Lauchmelder@feddit.de -2 points 2 years ago

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

[-] victorz@lemmy.world 1 points 2 years ago

I got confused. I was referring to the top-level comment in this thread, but that was actually posted by you, so... I got turned around.

But yeah, sounds about right, that the meme could be referring to the horrors in the h file vs the clean cpp file. ๐Ÿ˜„

[-] abrahambelch@programming.dev 4 points 2 years ago* (last edited 2 years ago)

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.

[-] bort@sopuli.xyz -3 points 2 years ago

drastically increases overall build times

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

[-] Lauchmelder@feddit.de 3 points 2 years ago

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

[-] bort@sopuli.xyz 1 points 2 years ago
this post was submitted on 22 Mar 2024
230 points (94.2% liked)

Programmer Humor

40886 readers
181 users here now

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

Rules:

founded 6 years ago
MODERATORS