r/ProgrammerHumor • • Jan 28 '23

Meme C++

Post image
53.9k Upvotes

1.5k comments sorted by

View all comments

Show parent comments

784

u/Tsu_Dho_Namh Jan 28 '23

My university did it the same way and it made me love C++.

"So convenient!" I thought, being able to use classes, and having destructors automagically deallocate resources for you. Plus getting to use strings instead of char* and vectors that we can resize at runtime. Not like those fucking C arrays.

Little did I know, pretty much every modern language is even more convenienter.

354

u/throw3142 Jan 28 '23

The problem isn't even that modern languages are more convenient. There is a real niche for systems languages with object-oriented features. The problem is that C++ is burdened by heavy backwards-compatibility requirements, it's unsafe by design, the ecosystem is a mess (it's so hard to link dependencies, compared to literally every other language including C and even raw assembly), and there is no consensus on style because there are so many ways to do the same thing (e.g. pointer vs reference vs rvalue reference vs smart pointer, #define vs constexpr, CRTP vs inheritance, throw exception vs return error code vs set errno, explicit cast vs implicit cast, lock_guard vs scoped_lock, #ifndef vs #pragma once, .cc vs .cpp file extension, .h vs .hpp file extension).

107

u/marti_2203 Jan 28 '23

Some of these things are solutions from different periods (smart pointers and the things before it, ifndef and pragma once) but I think the inheritance and CRTP solve vastly different problems. And thank you for reminding me about .cc vs .cpp

20

u/merlinsbeers Jan 28 '23

vs .C vs .CC

No really. There were people using .c for C and .C for C++. On Windows.

3

u/marti_2203 Jan 28 '23

When did this happen? What is the history behind this???

→ More replies (2)

35

u/throw3142 Jan 28 '23

Yeah I totally agree, each of these variants is different for a reason, and each one has its place. That doesn't stop them from being mixed together in weird combos and making the codebase completely unreadable lol

5

u/marti_2203 Jan 28 '23

Legacy spaghetti code sprinkled with technical debt, my favourite

→ More replies (2)

3

u/Tranzistors Jan 28 '23

There are good guidelines.

pointer vs reference vs rvalue reference vs smart pointer

  • reference when the target totally exists, recommended;

  • raw pointer when the target may or may not exist;

  • I.11 smart pointer when you own the resource and it lives on the heap;

  • local variable when you own it and it lives on the stack;

  • rvalue when the data doesn't need to live longer than the statement.

#define vs constexpr

ES.31 whenever possible use constexpr

throw exception vs return error code vs set errno

First of all, figure out if you are in an environment where you are allowed to throw. But if you can.

  • I.10 usually throw (e.g. failed to construct a std::vector);

  • if it's 'normal' that the operation could not deliver desirable outcome, return std::expected (e.g. smallest_prime_between(int min, int max);

  • errno is sad (E.28), only use in legacy, preferably wrap.

explicit cast vs implicit cast

explicit where reasonably possible; implicit is where dragons live.

lock_guard vs scoped_lock

CP.21

#ifndef vs #pragma once

SF.8 #ifndef, #pragma is non-standard. Or use modules (whenever they become available).

.cc vs .cpp file extension, .h vs .hpp file extension

NL.27; .cpp + .h

CRTP vs inheritance

C.hier. Cool guys prefer static inheritance, but I dunno.

→ More replies (1)

2

u/AssAsser5000 Jan 28 '23

This right here. I left cpp world to do java and I sort of feel like I wussed out and I sort of feel like I made a brilliant choice.

→ More replies (4)

66

u/sausage-superiority Jan 28 '23

I have imposter syndrome.

I’ve been trying to get motivated enough to learn C++. I use JavaScript and Python for work but I’m not a REAL developer because I don’t use C.

40

u/SmArty117 Jan 28 '23

Do you need to learn C++ though? Do you have your eyes set on a career in it that pays better or is more interesting?

Cause I have been writing C++ as a job for a few years, and I'm going through a book on modern C++ and let me tell you, the can of worms is deep and not pleasant at all. It feels great when you get something right that you struggled for, but sometimes it's just a pain to get anything working that in another language would be trivial.

30

u/sausage-superiority Jan 28 '23

Oh you’re absolutely right.

I’m fine for money. The ONLY reason for me learning C++ is that I feel inadequate for not knowing it. It’s purely vanity.

25

u/SmArty117 Jan 28 '23

Heh fair enough, I totally get wanting to do the "difficult stuff" just for self-esteem. I'd also consider Rust - also kinda hard to grasp, but pays off a lot better when you do IMO. Good luck!

4

u/ryan10e Jan 28 '23

I was going to chime in and suggest rust! I’m a month in and I still don’t get lifetimes, but everything else is really starting to click and it’s so satisfying.

→ More replies (3)

4

u/LittleCitrusLover Jan 28 '23 edited Jan 28 '23

Stepping out of the circle jerk, C++ is a very powerful language. I've never used a language with more capable metaprogramming, and the macro system + templates can express a lot of functionality with a given amount of code.

Rust is nice, easier in general, but still a headache. I write both languages for work (different projects have different needs). Rust is more fun and has better tooling, but you can make more things work in C++ on more systems. Plus pybind11 + numpy makes working with python a dream, since you're not limited to native python.

That being said, JS and Python are both real languages, and you can solve most problems with either. Anything you can't do in them directly, you can do in C++ and wrap, and have 99% of the benefits. I wouldn't sweat it. In my experience, python is easier to wrap with than JS.

→ More replies (1)

2

u/mallninjaface Jan 28 '23

Which book? I looked at C++ like 20 years ago and I'm thinking of taking another crack at it, but it seems a lot has changed...

4

u/SmArty117 Jan 28 '23

Effective modern C++

It's a set of guidelines for how not to shoot yourself in the foot with the features introduced since C++11.

But it's written for people who know at least C++ 98, maybe even some of the basics of C++ 11.

→ More replies (1)

18

u/Nighthunter007 Jan 28 '23

2

u/not_an_illuminati Jan 28 '23

Noobs. Real programmers disrupt subatomic particles to generate an energy burst that creates a new universe where the desired software will naturally come to exist.

2

u/Unfulfilled_Promises Jan 28 '23

TFW you split the atom in hopes of generating a better world for yourself in the next life 😭

0

u/[deleted] Jan 28 '23

[deleted]

→ More replies (2)

10

u/grimonce Jan 28 '23

You're not real because you don't use java.

4

u/[deleted] Jan 28 '23

Learn C. Read the original K&R. Fire up vim and mess around with some code. C let’s you go all the way down to assembly language. UNIX was developed alongside C. UNIX is the foundational OS for everything.

C++ is another beast entirely. I’ve studied it and written code in it but it feels far too unwieldy. Java is based on a stripped down version of C++ and even it’s a handful.

2

u/[deleted] Jan 31 '23

Lucky you. My university still makes us use fucking C right till the end, we have to argue and fight with our profs to allow us to use C++ or Python or Java or pretty much anything other than C

2

u/Tsu_Dho_Namh Jan 31 '23

Really? Oh man, that sucks. We used a bunch of stuff.

Scheme in first term to learn functional programming (and then never again)

C in second term.

C++ in both terms of second year. Plus Bash cause they were teaching us Linux. The networking class had us working mostly in the Linux terminal.

Third year had a mix. The compilers course was taught in assembly and a small subset of C (we made a basic C compiler). Operating Systems class used C (cause we were building and modifying a kernel). User interfaces was taught in Java. And the intro to AI class we could choose our language, but they strongly recommended python.

Fourth year your classes were based on your electives and what specialty you wanted to go into, but they had a wide range of languages. I took machine learning which was in python.

→ More replies (1)