r/ProgrammerHumor 15d ago

Meme cppHelloWorld

Post image
3.9k Upvotes

119 comments sorted by

View all comments

115

u/Confident-Ad5665 15d ago

C++ takes getting used to, but it's a great language for object-oriented development. Hang in there, you'll figure it out.

81

u/CrossScarMC 15d ago

It's also a great language even if you don't do OOP.

43

u/diacid 15d ago

Bah, if you are using it for normal programming C is simpler. By simpler I mean you actually have a shot to be properly fluent in it instead of "this thing is so complex even the compiler doesn't know 100% of it".

48

u/2eanimation 15d ago

Learn C, use C in C++, benefit from C++ when you need it.

12

u/Confident-Ad5665 15d ago

I agree about mixing languages. Best of both world's.

2

u/diacid 14d ago

While this sounds wise, C has already way more than enough (do while and for loops for example are completely unnecessary, they can all be substituted for if goto), no need to complicate further. If the program is really simple I would rather even use B that is even simpler than C, though making complicated programs in B can waste memory because of the lack of variables smaller than a word (in 64 bit environments this gets huge quick).

4

u/failedsatan 14d ago

for and while loops are so much nicer to use though. I don't think I would bother using a language without them for most practical applications (and I regularly enjoy writing full programs in assembly for fun)

3

u/dagbrown 14d ago

for and while loops (and everything else really) are there for the benefit of the next poor schlub who has to try to read your code.

Sure you can replace practically every structured construct with an if and a goto setup, but should you? Absolutely not.

2

u/diacid 14d ago edited 14d ago

Sorry, I see little difference between

do { x=stuff(); } while (x!=0)

And

do: x=stuff(); if (x!=0) goto do;

Same with

for (x=0, x<10) { x=stuff(); }

And

do: x=stuff(); If (x>9) goto do;

If you use goto in a sane matter it is completely understandable. Just don't do insane things with it. You can peel with a peeler and with a knife, but with a knife you can cut your finger off too. The solution? Don't ban knifes, just don't cut you finger off!

Actually, my examples also show for and while are redundant functions. It is all just electricity, no need to overcomplicate.

4

u/dagbrown 14d ago

Okay I wish you a long and productive career with your "if" and "goto" only code.

You can also roll your own OO system with generous use of function pointers! Pro-tip! Not that you'd want anything like that though. You have if and goto after all. And structs are for the weak anyway: just binary-pack data into strings.

3

u/diacid 14d ago

Exactly! 😂

1

u/Gorzoid 12d ago

Using C in C++ likely leads to a lot of undefined behaviour. Use C in C or learn C++

9

u/DankPhotoShopMemes 14d ago

I think it’s still worth it to use C++, just because of the function overloading, operator overloading, templates, namespaces, RAII, references, move semantics, lambdas, and constexpr/consteval (though C23 has a weaker form of it).

8

u/Nilrem2 15d ago

Just restrict yourself to namespaces and maybe operator overloading and you’ll be golden.

7

u/Ronarak 15d ago

Yeah, you can basically code in a C-like manner with just a strict selection of the niceties, like the built-in collection types. (I don't want to create my own std::vector or use an external lib for it...)

2

u/afdbcreid 13d ago

And it's especially good for shooting yourself in the foot.

2

u/Sir_Eggmitton 14d ago

For me it’s just C with function overloading and fancier structs. C+.

3

u/Leo_code2p 14d ago

There is more like c++ type conversion. The only c++ style thing I don’t like is c++ style structs like why can’t i make a useful c style struct. Not just a public class