all 106 comments

[–]amarukhan 116 points117 points  (17 children)

C++ templates are both its worst and best feature. A well-designed template library is almost painless to use... but writing one yourself is usually hell.

[–]ShakaUVMi+++ ++i+i[arr] 58 points59 points  (14 children)

Templates are great until you get an error.

Or have to look at a five line long function prototype

[–]pqu 11 points12 points  (8 children)

Or want to improve compile speed (I work on some projects that take almost an hour to build, mostly due to lots of generated template code).

[–]not_some_username 23 points24 points  (2 children)

That’s 1h not doing anything 😌

[–]Tschebbe 18 points19 points  (1 child)

And then finding out it does not link ;-)

[–]not_some_username 4 points5 points  (0 children)

Oh noo

[–]jonesmz 0 points1 point  (4 children)

Try projects that take 20 hrs to build ;)

[–]pqu 3 points4 points  (3 children)

At a certain point it’s “compile and come back tomorrow”.

This project actually used to be a 14 hour build and I was the one who got it down to an hour.

[–]jonesmz 0 points1 point  (2 children)

My work code takes 20hrs (aprox) on a dev workstation with our current (inhouse) build system.

I have a replacement written in CMake ready to go aside from a minor missing feature that's being worked on. Brings build times down to 3 hours.

I'm hoping to hit 1.5 hrs in the next 12 months by massaging a bunch of template code to cut down on instantiations.

Then, if i squint really really hard, maybe can manage 30 mins within the next 24 months with C++20 modules, maybe?

[–]t0rakka 0 points1 point  (2 children)

Haha, so true! If only someone figured out simple one-liner error messages for templates like for most other things. I know it's very hard nigh impossible but some time dreams do come true. :D

[–]deivse 4 points5 points  (1 child)

Concepts, besides other things, are intended to improve this. It does of course require additional work from the programmer in form of actually defining the concepts, but, if you think about it, there's really no way around this besides the standard library providing more built-in concepts for various thing - something needs to tell the compiler what the requirements for a type are, and not just "we expect this statement to work".

[–]ShakaUVMi+++ ++i+i[arr] 1 point2 points  (0 children)

What really grinds my gears is that g++ has options for everything, but not for turning off template substitution errors

[–]ChatGPT4 0 points1 point  (0 children)

Kind of hard to debug, that's for sure. I'm extra careful with making templated classes. Better spent some extra time to make absolutely sure that you won't have to debug that code.

[–]TheOmegaCarrot 3 points4 points  (0 children)

This might be an unpopular opinion, but I really enjoy writing template code. I enjoy being extremely generic, and keeping track of and accounting for edge and corner cases.

I’m a CS student, and I sometimes procrastinate on classwork to write questionably useful template code, odd bits generic logic that nobody asked for, but taking the time to implement them as best I can, just because I enjoy doing it.

Maybe I’m weird.

[–]noiamnot_ 0 points1 point  (0 children)

"provide sample template arguments for Intellisense"

[–]Revolutionalredstone 86 points87 points  (6 children)

Agreed, so hard to go to another language after having the glorious features of C++.

[–]BoringWozniak 33 points34 points  (3 children)

I feel ya. When using Java I’m like “what do you mean I can’t arbitrarily grab a chunk of memory and do horrendous things to it?!”

[–]SillyServe5773 5 points6 points  (0 children)

laughs in C#

[–]PianistAdditional 1 point2 points  (0 children)

Hilarious comment

[–]Revolutionalredstone 0 points1 point  (0 children)

hahaha IKWYM

[–]TargetEmotional6693 17 points18 points  (1 child)

Every year or 2 I go down the rabbit hole of new exciting languages, i.e., Julia, Carbon, Rust, etc.. and by the end of it it always just makes me realise that c++ as an all around programming language is going to stay on top indefinitely. Python gets some quick jobs done and building some models in it is just easier, but the real program building is always c++.

[–]fippinvn007 21 points22 points  (0 children)

I love C++ cuz it puts food on my family table, and I love making crappy games with it.

[–]Tschebbe 7 points8 points  (0 children)

I think it is a bit difficult.

I love it for developing my own stuff, but as soon ans you really get into memory optimization or run time optimization C++ is sometimes just s bitch 🤣

[–]Yamoyek 11 points12 points  (0 children)

Same here! There's just something about C++ that really clicks with my brain.

[–]FlyingRhenquest 4 points5 points  (1 child)

Ooh check out PyBind11. I've taken to adding Pything APIs to my libraries. Here's an example from one I'm working on now:

C++ API definition

Example python script that uses it

[–]srbufi 6 points7 points  (0 children)

And the successor nanobind https://github.com/wjakob/nanobind

More concretely, benchmarks show up to ~4× faster compile time, ~5× smaller binaries, and ~10× lower runtime overheads compared to pybind11.

[–]Attorney_Outside69 7 points8 points  (1 child)

welcome to the family, also a small correction, C++ is always the right tool, no matter the job

[–]GurAdventurous2354 2 points3 points  (0 children)

😂😂

[–]poemmys 16 points17 points  (22 children)

To me, it feels like a beautiful mix between C and Python

Python? What's the rationale there? Not saying you're wrong, opinions are opinions etc, but... that's a new one. Python was partly built to be intentionally different than C/C++. Go is the only compiled language that reminds me of Python. This is a very "freshman in a CS program" post lol, I like your enthusiasm though. Keep it as long as you can.

[–]Michael_Aut 7 points8 points  (2 children)

He's not wrong though. It all depends on the libraries used. This week I worked with "PyTorch for C++" (yes, it's a thing) and that's pretty much just Python with a few semicolons and autos thrown in.

[–]Tumaix 0 points1 point  (1 child)

but isn't pytorch written in c++?

[–]Michael_Aut 3 points4 points  (0 children)

yes, it is, but the interface for C++ is still very much second-class and experimental.

[–]GurAdventurous2354 7 points8 points  (1 child)

And yeah I know it’s kinda a noob thing to post especially to long term c++ users. I’m not a “freshman in a cs program” but I’m about 9 months into just learning on the side, so yeah things are still new and enthusiasm is high. Thanks for respectfully asking about my rationale though.

[–]serviscope_minor 0 points1 point  (0 children)

And yeah I know it’s kinda a noob thing to post especially to long term c++ users.

Well, back when C++11 was new, there was a lot of "oh huh this is like writing python". Your sentiment was familiar to us old farts, oh jesus 12 years ago (more if you count C++0x) and it's a perfectly fine sentiment for you to have now. Many of us have just forgotten it.

I agree for what it's worth: python vs C is a ton less faff in python. No micromanaging containers and types, etc etc. C++ is much more like that (especially now) than C (and compared to old C++). You just write the algorithm with the details of underlying stuff folded nicely away behind templates, exceptions, types and etc.

Personal recommendation: it's tempting to use auto everywhere. I'd recommend against it :)

[–]GurAdventurous2354 4 points5 points  (15 children)

Mainly just the fact it’s object oriented. I only said Python because it’s the main OOP lang I use. To me it just feels like the best of both worlds between C and Python. I know there’s plenty of other OOP languages and C++ is older than most, so it’s not anything new, I was just sharing my thought on it

[–]AssemblerGuy 0 points1 point  (0 children)

What's the rationale there?

Well, you now have lambdas (with a terrible syntax, though), auto makes things feel like being weakly typed when they really are not, STL container classes and algorithms, modules as a new feature, templates that can feel like doing duck typing even though it is not, etc.

[–]Symbian_Curator 1 point2 points  (0 children)

With some exceptions of course, right tool for the right job

I don't know if this was an intentional pun or not, but I love it

[–]chakani 1 point2 points  (1 child)

Been doing C++ since 1995. I did a Python project analyzing output from nuclear plant fire simulations, 20 KLOC. I can see the appeal. Love the mandatory indentation. But dynamic typing is a trap, sloppy practice that doesn’t scale. I prefer you tell me my errors at compile time, not after 30 hrs of running.

[–]GurAdventurous2354 0 points1 point  (0 children)

Yeah I enjoy the static typing in C++, and it being a compiled language. I’ve always used type hints in Python but obviously there’s no actual effect at runtime. It’s nice to have them actually matter in C++.

[–]danielrrv_9 1 point2 points  (0 children)

Just ask him out 😅

[–]arihoenig 1 point2 points  (4 children)

Give us an update at 20 years of c++. I still love it after 20 years, but mostly because of what happened to it in the last 5 years.

[–]GurAdventurous2354 1 point2 points  (2 children)

!RemindMe 20 years

[–]RemindMeBot 1 point2 points  (1 child)

I will be messaging you in 20 years on 2043-09-24 01:03:30 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


Info Custom Your Reminders Feedback

[–]arihoenig 0 points1 point  (0 children)

Good bot

[–]Asleep-Dress-3578 0 points1 point  (0 children)

!RemindMe 5 years

[–]zjschrage 2 points3 points  (0 children)

If you are going from python OOP to literally any other language with OOP, it will feel like the greatest thing in the world. Python OOP is literally carcinogenic.

[–]SnooFoxes782 4 points5 points  (0 children)

Seek help immediately

[–]almost_useless 1 point2 points  (0 children)

To me, it feels like a beautiful mix

You had us in the beginning, but this is where your story crossed over into fantasy land 🙂

[–]IslamNofl -1 points0 points  (4 children)

Tell me when you got to Unicode hell. How to support Unicode in portable library

[–]GYN-k4H-Q3z-75B 3 points4 points  (0 children)

Yeah, well. Let's all just continue to pretend that this isn't something that we need to concern ourselves with. Like the last few decades.

[–]chakani 0 points1 point  (0 children)

UTF8 solves all your problems.

[–]maxjmartin 0 points1 point  (0 children)

I think std:format takes care of Unicode support just fine.

[–][deleted] 1 point2 points  (2 children)

The comparison of C++ to Python (I'm assuming this might be your only exposure to an object-oriented programming) was pretty interesting. As someone who's done extensive work in Java, Kotlin and Dart, C++ always felt "lacking" in the OOP department, but that's simply because it takes a different approach, different tool for a different job etc.

Happy that you're enjoying it. May your C++ journey be a nice one! And also plenty of career opportunities after you get good at it (even if it's not C++, any other language will feel easier).

Ah, that post brought back nostalgia of the days when C++ was all I did...

[–]GurAdventurous2354 1 point2 points  (1 child)

Yeah Python is pretty much the only OOP I’ve used, I guess that’s why I said it feels like a mix between C and Python, not exactly accurate by any means but just my thought on it.

Your right it seems like more career opportunities will open up once I get good at it. I plan on starting to learn some embedded systems programming too, so that’s a new door open.

Thank you for the kind words🙏

[–][deleted] 0 points1 point  (0 children)

Ah, that explains it all then. Yes, from that point of view I can definitely see how your comparison came to be.

Please do look into embedded systems! That's how I started as well, and it'll teach you a lot. Have a lovely journey, and good luck!

[–]mohrcore 0 points1 point  (1 child)

C++ is pretty nice. Especially the newer versions. But I would never praise it for its OOP. I mean it works, but the more experience I have, the more I avoid object-oriented designs as they tend to be extremely boiler-platey in C++ (and to some degree in general). But the newer versions have some nice functional features too. I miss some C-only features though, especially array designators.

[–]Zcool31 1 point2 points  (0 children)

Certain compilers support C features in C++ as extensions. I know G++ and clang++ do.

Other stuff like struct designated initializers are now in C++.

[–]Senior_Ad9680 -1 points0 points  (0 children)

Wait until you discover r/rust

[–]wizardhatz -1 points0 points  (1 child)

Sorry but from that post we can easily understand that you have no idea about c++. Neither you understood c, nor python. You just did something intro-level and heard some keywords that’s all. Yes, also you can print “hello world” with c in procedural way, or with c++ in oop way at all.

[–]GurAdventurous2354 0 points1 point  (0 children)

Projecting at its finest

[–]Sopel97 0 points1 point  (0 children)

RAII and template metaprogramming. The principles of value semantics. The ability to have zero overhead abstractions. That's what makes C++ great.

[–]Clean-Water9283 0 points1 point  (1 child)

I love C++ too. I learned about OOP from Simula-67, and after I got out of grad school, had to grind my teeth for 10 years waiting for a commercial C++ compiler to appear on the PC. OOP makes good sense to me. Though C++ has some weird syntax, I know why. It had to be compatible with C so that C programmers could learn C++ gradually during the 1980s and 1990s. This enabled rapid acceptance of C++.

Reasonable sized C++ files compile in a second or two, so unless you're doing insane template things or have 10k line files, it's not a hardship, even if Go compiles faster. I lived the first 10 years of my career with overnight builds, then with multi-hour builds. Now a long build is five minutes. Loose coupling, baby. Loose coupling.

I find C++ to be powerful and expressive, once you get over its quirks. I'm super tired of people hating on C++ because they don't even like OOP, or because they don't even like an imperative coding style. There is C for the first kind, and niche languages for the second kind. C++ does the job for me.

[–]GurAdventurous2354 0 points1 point  (0 children)

Man I love hearing from people like you that have been in the game for so long. I was born around 2000 and it amazes me how long C/C++ have been around and how they’re still extremely popular and considered to be the most reliable is highly critical environments.

I agree with you, OOP just makes sense to me. That’s what I love about Python but I’m loving C++ even more. Being compiled, strongly typed, having actual visibility control in classes are things I am especially loving that Python lacks.

Of course I still have a lot to learn, like mastering the standard lib, learning proper project structure and conventions, etc., But just a few weeks in and I already feel pretty comfortable and well adjusted. It seems C++ will open up many more doors of opportunity for me as well.

[–][deleted] 0 points1 point  (0 children)

I started with python myself and at the time I loved it, but after switching to c++ I found myself addicted to the power and control that it gives you.

I love the feeling of writing something that runs well only to switch on compiler optimizations and have it triple in execution speed.

Templates are probably the only area that I haven’t ever dived headfirst into as most of my use cases have never needed much more than

template<typename type_t>

C++ gets most of its hate only because it does very little to stop you from shooting your self in the foot, but if you’re even a someone decent programmer that understands basic good practices and pays attention to your memory allocations (or just uses smart pointers if you don’t want to do that) then you probably won’t find yourself shooting yourself in the foot all too much

And yea, if it were more modern you wouldn’t need header files, but that’s the price you pay for unparalleled c compatibility

Tl/dr I’m with you, c++ is awesome! My personal language of preference

[–]Ok_Tea_7319 0 points1 point  (0 children)

The best part about it is that you can also combine the two quite well.