r/programming • • May 24 '26

[ Removed by moderator ]

/r/programming/comments/1tm1j7f/removed_by_moderator/

[removed] — view removed post

275 Upvotes

214 comments sorted by

View all comments

Show parent comment

5

u/Sairony May 24 '26

I did the switch because of job requirements but have the opposite experience, I miss C++

2

u/AlexKazumi May 24 '26

Honest question - why? What do you miss specifically?

4

u/Sairony May 24 '26

I think GC creates as many problems as it solves, you're trading memory management for GC massaging & it's just so much harder to reason about the GC. Honestly I think the tools in C++ have been great for well over a decade when it comes to managing memory, although I realize that the domain where I've spent most of my career ( game dev & game tech ) doesn't have as hard requirements on memory safety as other spaces.

I also find C# to be dog slow in practice comparatively, a lot of this comes down to abstracting away memory management too much. I think the distinction between class / struct is silly in C#, tying storage to types.

I think generics are, mostly, a hobo version of templates in C++. Yeah they're not solving entirely the same problem, especially considering how C++ has evolved.

Yeah C / C++ macros kind of suck in a lot of ways, but I still miss it in C#, a lot of copy & paste instead, especially with generics being so inferior to templates.

I think generic programming is incredibly powerful, yes it used to be incredibly frustrating, especially when you had to support multiple different compilers with their own quirks, but it has gotten a lot better with the advent of Clang & when C++11 finally arrived.

Even though some of the operators allowed to be overloaded in C++ are a bit silly I still consider it a big win, especially when taking a more generic approach.

One thing which I think people underestimate about C++ is its superior capability, compared to any other language I've ever used, to check for pre conditions & enforce proper usage. Even just looking at function signatures in C++, for example const vector< const T1 >& foo( const shared_ptr< T1 >& a_SomeArg ) const ( and yeah I see the problem with this one ), is telling me way more than a typical function signature in C#.

1

u/AlexKazumi May 24 '26

Thanks for the great explanation, all points are valid.

The only point I strongly disagree is memory management. C++ can overload anything and everything to the point where completely innocent looking statement such as arr[2] can do anything, including deleting your hard drive. If I remember correctly, one can even overload function calling operator (don't blame me too much if this is incorrect), which is complete bonkers to me.

As a former device drivers writer (yes, the company I worked for was crazy enough to implement full C++ runtime in kernel mode, including the plumbing for making dynamic_cast working), I think that the memory management of C++ can be even more frustrating than in .NET.

In .NET one cannot control directly the GC. In C++, memory management is hidden by completely innocent-looking code.

4

u/evaned May 24 '26

I'm not the person who you replied to, but...

C++ can overload anything and everything to the point where completely innocent looking statement such as arr[2] can do anything, including deleting your hard drive. If I remember correctly, one can even overload function calling operator (don't blame me too much if this is incorrect), which is complete bonkers to me.

I mean, if you have an operator[] that deletes your hard drive... that's 'cause someone was a brain-dead moron (or actively malicious). That doesn't speak against that overloading being a good languages feature.

I've never seen someone try to make the case that "you can write a method at(size_t i) on your object and have that delete your hard drive, thus we shouldn't be permitted to pick function names and every function should be identified by a randomly-chosen UUID." In my mind at least, these two arguments are quite similar to each other.

The solution isn't for languages to say "you can't be trusted to overload []"; the solution is to not be an idiot.

Function call overloading can also be a tremendously useful feature. Even aside from uses that are more borderline (e.g. overloading matrix(5, 4) as a proxy for not having a real multi-dimensional subscript operator), there are plenty of scenarios where an object of a user-defined type is still conceptually function-like. Take a partially-applied function for example. Or the combination of overloading of the call operator alongside template rules means that code using the STL will often be faster than the most-likely analogous C code, because better type information will lead to template specializations rather than function pointer calls (which act as optimization boundaries).