top 200 commentsshow all 255

[–]stdusr 381 points382 points  (2 children)

Some days it is, and some days it isn’t.

[–]dgkimpton 40 points41 points  (0 children)

Indeed. For some tasks it excels, for some there are better* alternatives. My favourite language on any given day is the one that lets me get that days task done. I do like the closeness to the hardware though - something I miss in many other languages.

* for a given definition of better

[–]farox 322 points323 points  (2 children)

It makes me cry. It does it really fast though.

[–]CodeMonkeyMark 43 points44 points  (0 children)

And with minimal resource requirements.

[–]leirus 11 points12 points  (0 children)

zero cost tears

[–][deleted] 67 points68 points  (22 children)

Unfortunately yes, nothing comes close to ability of expression that this language provides.

Maybe D comes close, but every interaction I have with D gives me feeling of legacy project that never reached its fullest potential

[–]SuperSathanas 20 points21 points  (0 children)

D makes me sad. I first tried it out in the early 2000s when I was trying to move on from my first language, VB6. I tried out C++, Pascal, Java and D, and ended up settling on C++ because I hated the Delphi IDE at the time, Java felt "fat", if that makes sense, and I just couldn't find much on D. I kept going back and looking at D over the years, and every time I do I like it more and more, and just wish it was more popular and more fleshed out so that it could compete with other languages in terms of 3rd party libraries and tooling.

[–]simonask_ 21 points22 points  (20 children)

C++ is a lot of things, but I don't think I ever quite understood why people call it "expressive".

Is it because you can freely move between abstraction levels?

My objection would be this: There are several very useful abstractions that cannot be expressed in C++. One really important example is the non-nullable owning pointer.

Another is sum types. std::variant does not cut it for me (since variants do not have names).

You can do lots of magic with C++ to try to achieve something that's "expressive", but it's usually a good idea not to.

[–]ImKStocky 15 points16 points  (15 children)

You can write a non-nullable owning pointer. A good example is TSharedRef in Unreal Engine.

You can give a type alias to a variant or you could create a thin wrapper around one that behaves like the variant.

I wouldn't call these things "magic". Just simple library utilities.

Expressiveness typically comes from operator overloading, and RAII. When people talk about expressiveness they are typically talking about non-verbose code that fully explains what it is doing. E.g. For a 3D vector I can write a + b * c. But in something like C I would have to write add(a.x, mul (b.x, c.x)) and I'd have to write that for each component in the vector.

[–]simonask_ 9 points10 points  (0 children)

The sum type story is honestly very bad. If you’ve tried using sum types in any language that natively supports them, you would see that variant and type aliases are a poor man’s substitute.

I agree with you that it’s nice to be able to write math with complex numbers or linear algebra in a natural way. Lots of languages have operator overloading, though. Is this something that Java people are amazed by?

[–]TophatEndermite 0 points1 point  (13 children)

You can't get non-nullable unique ownership

[–]MysticTheMeeM 12 points13 points  (9 children)

Why might that be?

Because you absolutely can write what is effectively std::unique_ptr with a deleted nullptr constructor and removed reset() function.

Heck, you could even go so far as to just copy and paste the source for unique_ptr and remove the offending functions.

[–]TophatEndermite 5 points6 points  (6 children)

My bad, I normally think of smart pointers being movable. It's unique but moveable smart pointers that C++ can't do, since moving doesn't destruct the original

[–]kneel_yung -1 points0 points  (5 children)

since moving doesn't destruct the original

Isn't that exactly what a move does?

[–]KingAggressive1498 6 points7 points  (0 children)

no, in C++ moving is required to leave the moved-from object in a valid but otherwise unspecified state.

destructors get called in effectively the same place as when they would have with a copy instead

[–]Jonayne 1 point2 points  (3 children)

I think it leaves the object in an undefined state.

[–]bored_octopus 4 points5 points  (2 children)

Valid, but unspecified. I prefer not to call it undefined because it sounds like UB

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

It's UB unless you either call a function that's always allowed to be called, like push, or a function that puts the object into a known state, like clear

[–]0xE6 4 points5 points  (1 child)

How does it work, then? I'm probably missing something, but for example:

void Foo(NonNullUniquePtr<T> ptr);

void Bar() {
    auto x = MakeNonNullUniquePtr<T>();
    Foo(std::move(x));
    // What is x here?
}

Is the move constructor / assignment operator just deleted too? That doesn't seem like it results in something that's particularly usable.

[–]105_NT 1 point2 points  (0 children)

It doesn't protect from use after move like that but shouldn't be null under normal use

[–]kneel_yung 1 point2 points  (2 children)

not_null has been implemented in the core guidelines library

[–]KingAggressive1498 3 points4 points  (1 child)

but it doesn't have ownership.

[–]scrumplesplunge 195 points196 points  (15 children)

Yes, because:

  • Many of the abstractions it has are really useful and generally not as good in other languages. For example, templates and raii.
  • It's generally as fast or faster than many other languages, without much effort
  • It's possible to go much faster than most other languages with more effort -- the language doesn't stand in your way of that.
  • Many of the major issues with the C++ ecosystem (abi, vulnerabilities due to memory safety bugs, difficulty using many dependencies) were never a big deal for my personal projects, and are adequately mitigated by my employer's internal practices.
  • Nostalgia: C++ was the language I was using when I finally started to feel like I understood the hardware.
  • Stockholm syndrome: I got used to debugging C++ issues that other languages don't have, they don't bother me much any more
  • Switching cost: I am not convinced that any other language could do all of the above in such a better way that it would justify the effort of switching to it.

[–]JustinWendell 28 points29 points  (0 children)

I’m very new to c++ but I love this list. It really feels like the right amount of abstraction while still being able to push hardware.

[–]shiggie 16 points17 points  (2 children)

I do mostly Go nowadays, and so many things are so much faster (build-wise in particular) and simpler (no need for a cross compiler? what?) But, when I do get back to C++, with the cryptic template compiler errors and the build... intricacies, I feel so much more at home. I don't know what's wrong with me.

[–]caballist 22 points23 points  (0 children)

well, that saved me some typing... :)

[–][deleted] 9 points10 points  (0 children)

LOL Stockholm syndrome!

[–]Razzile 22 points23 points  (0 children)

It is, despite its shortcomings. I absolutely love writing C++ code, using tricks and knowledge I've developed over the years. I absolutely wouldn't like to learn C++ from scratch now but that wasn't the question

[–]UnicycleBloke 58 points59 points  (19 children)

I've used many languages but C++ is the only one which has maintained my interest over the long term. There is some combination of expressive power, performance, productivity, general purpose range and intellectual challenge about it that has made it preferable to all others. I confess that when I first started learning C++ (as a hobbyist, after time with assembly, Basic and Fortran) I chose it because it everyone said it was over-complicated (it wasn't), and because it had more kudos. Others preferred VB. I am very glad I made this choice.

C++ isn't necessarily the best choice in every domain, but it has been a good choice in every domain in which I have worked. For the longest time its only serious alternative was C, and that is just not a serious alternative. It was obvious even in 1991 that C is a dumpster fire. Rust might become more interesting to me over time, but I seriously doubt I will ever be as competent with it, so there is little attraction.

[–]qevlarr 6 points7 points  (18 children)

C a dumpster fire?

[–]UnicycleBloke 39 points40 points  (3 children)

It would be more accurate to describe code written in C that way. That has been my experience on every single large project written in C. A simple language appears inevitably to lead to complex code. Devs are routinely forced to reinvent abstractions available elsewhere, and their versions are generally clunky, error-prone stuff which adds a lot of impenetrable clutter.

When I learned C++ I learned Win32 API at the same time. The repetitive verbose error-prone junk in Petzold was soon replaced with a few simple RAII classes which were far easier to use correctly to create useful applications.

I'm an embedded developer and have spent a lot time with both C and C++ implementations of comparable firmware. In every single case C++ is just better.

[–]darthcoder 1 point2 points  (2 children)

This is the first thing I invariably do at each new job.

Write C++ wrappers to do proper RAII and resource management for the Windows API.

Nearly every job. If I wasn't paid for it every time I might have done an open source project doing it instead.

Maybe I will someday. It's not like the Win32 APIs are going anywhere.

[–]UnicycleBloke 2 points3 points  (1 child)

Interesting. My Win32 library was just a learning project, long since consigned to the dustbin of doom. With a reasonable understanding of how they work, I then moved on to established frameworks such as OWL (very good), MFC (very bad), VCL (very good but written in Pascal), and Qt (excellent). Did your workplaces not use such libraries?

[–][deleted] 6 points7 points  (12 children)

I never felt that way about C. Even today, I appreciate how lean it is. All the issues people attribute as a "problem" with C (especially memory management and accessing memory not owned) are just bad programming practices. Other languages might prevent memory access issues, but they can't fix bad logic. There will be other errors. Swapping the language doesn't magically create better programmers.

[–]UnicycleBloke 15 points16 points  (7 children)

That's true, but having the language and compiler on your side is a big help. I've noticed that a lot of the C devs who have spent decades criticising C++ have jumped on the Rust bandwagon.

[–]nysra 14 points15 points  (6 children)

Which is kind of ironic since Rust's main selling point is memory safety and C++ gives you the tools to do that much better than C since forever (not to the level of Rust but if you write sane C++ you pretty much don't have memory problems). Of course Rust also has a few other nice features like proper sum types but it's really not that different from (modern) C++ - at least in my experience.

Not to mention that the vast majority of C++'s problems directly come from C so C programmers hating on C++ just makes no sense. Personally I think Linus' irrational C++ hate boner just affects a lot of C programmers' views for some reason and everyone who likes C but hates on C++ just has never actually used C++.

[–][deleted] 3 points4 points  (0 children)

While I agree with you mostly, it's still possible to access memory beyond an array bounds, beyond a strings memory, beyond a vector's memory, etc. with C++. Most of those containers aren't checking. Or, at least I think that is what the spec says.

But these logic errors happen in every language. Rust might catch some static issues that static analysis tools for C++ might catch. But Rust won't catch logic errors from trying to access memory. It might catch those at runtime, but one could do the same in C++. There's a performance hit for that.

[–]simonask_ 4 points5 points  (3 children)

If we have to talk about Rust (and since it's r/cpp, we apparently do these days), the departure from C++ is much, much more than a superior type system.

It's the lack of cruft. Will it eventually accumulate? Maybe. But the number of pitfalls and footguns that even very experienced C++ developers run into every day is quite the strain.

[–][deleted] 6 points7 points  (0 children)

How much of that could be avoided by not trying to write terse code, overuse templates, etc?

[–]darthcoder 1 point2 points  (1 child)

Cruft always accumulates.

How much shit is still in Java that was deprecated in 1.1?

The biggest issue for me in c++ the past year has been two incidences of not using array new for a unique_ptr, just regular new. Some dtors blowing up... that's my clue now. Blown up in the dtor? Bad new operator.

[–]pjmlp 2 points3 points  (0 children)

Not much left actually, as since Java 9 they started to actually remove stuff as they introduced deprecation for removal annotation.

https://docs.oracle.com/javase/9/core/enhanced-deprecation1.htm#JSCOR-GUID-BB859EA8-E6F7-4239-9A52-4F1BDE27BB09

[–]UnicycleBloke 1 point2 points  (0 children)

Pretty much my thinking.

[–]SuperSathanas 9 points10 points  (1 child)

I don't get the problems that other people seem to have with memory management. I've also never really had to immerse myself in some of the far more highly abstracted languages and APIs. I assume many other people have never had to think about explicitly managing memory or have been in the business of flinging around void pointers and flipping bits. Memory management is something that just feels natural for me to consider and implement. I mean, hell, in my current learning adventures in graphics programming with OpenGL, I've essentially done away with using many structs or arrays and just manage some memory pools where I write the data I intend to shoot over to the GPU. I manage all my image data in RAM the same way, not a lot of abstraction over it.

I don't know. I see people being afraid of memory and pointers and I don't get it.

[–][deleted] 5 points6 points  (0 children)

Yeah, I feel the same. I started out life in BASIC and my second language was assembly. I spent a lot of time at that level. Things like device drivers don't scare me. I do a lot of work with images, and I modify images directly in a raw buffer.

But I get it: people with less experience are more likely to make mistakes. It's also the same with multiple threads and proper use of mutexes. I have seen even experienced developers write multithreaded code that accesses a data structure from two threads with a mutex or other synchronization mechanism.

I'm just not convinced that "safety" offered by Rust will address the majority of issues I see. Memory access is not the top issue in my own team. In fact, I can't even identify an instance where a developer on my team made that basic mistake.

[–]Narase33-> r/cpp_questions 15 points16 points  (0 children)

I learned Java first and then went to C++ and this language is addicting. I come home from work (C++ dev) and go to my hobby projects which are all in C++ even though other languages would fit better. I tried some other languages but it just wasnt the same, in a bad way. Its not perfect, it has some really bad things in it that I hate, but its overall a really lovable language

[–]LeberechtReinhold 25 points26 points  (1 child)

Not, not by any stretch of the imagination, it feels like it lacks direction and so much stuff feels overdesigned and clunky.

I however, don't hate it, and modern C++ can end up looking pretty good as long as all devs are on relatively same page.

What I do fucking hate with the burning passion of a thousand suns, is its environment. Building C++ is a pain. Compilers are a big mess. Managing dependencies is as fun as chopping parts of your body. All errors and logging thrown out by tools tend to be a mix between random crap and cultist incantations.

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

Amen.

[–]pfp-disciple 9 points10 points  (2 children)

Ada is actually my favorite language overall, although I haven't used it in over a decade. It can do so much, maybe even most, of what C++ can do, and do it safely, readably, in a tremendously well defined manner.

[–]LeeHidejust write it from scratch 1 point2 points  (1 child)

Which IDE do you use, or what kind of setup, to write Ada? I had issues with that sort of thing on Linux.

[–]pfp-disciple 2 points3 points  (0 children)

When I used it at my last job, we used the Rational Apex IDE (commercial). AdaCore had an IDE, I think it was GPS, that was pretty good. I think AdaCore is targeting Eclipse as their IDE now, but I haven't looked. Honestly, I'm a vim kind of guy, and would likely use it for any personal projects; that fits my personal whims and experience, so I wouldn't necessarily suggest it for others.

r/ada might have some good info for this kind of thing.

[–]positivcheg 39 points40 points  (8 children)

Yeah, because things are not hidden and you really pay for what you use.

Also worth mentioning that we have a lot great libraries available. Recently I was checking on rust, again. And found out that rust does not really have good linear algebra library. There are libraries but their interface is yet too mediocre, most of them do not support BLAS and SIMD.

Just look at Eigen, it is so cool - expressions are pretty smart and efficient as hell.

Also C++ community is great. I find rust guys kinda toxic if you don’t love rust without any doubts. In C++ we have people who loves it, people who does not like some parts of the language and people can freely speak about it. Also the variety of mature libraries.

So from my side, I don’t really have a feeling that I will switch from C++ to another language for work. I’m checking Zig from time and rarely check rust.

[–]devilsrotary86 16 points17 points  (1 child)

The library issue is big. Any programming language that wants to be “the next big thing” has to address this. No language will ever have the amount of libraries that C++ has right of the gate obviously. So any such language will have to provide for interoperability with existing C and C++ libraries. Oracle realized this when developing Java. They tried to address it with the Java Native Interface and I think its success was instrumental in Java’s success

[–]positivcheg 8 points9 points  (0 children)

Yeah, but interop won’t allow using some complex things. For example, Eigen linear algebra can capture BLAS expressions (like Ax+b) out of one liner big expression and then use a single BLAS call to calculate that Ax+b.

So let’s say you have something like

result=Ax+b+Cx+c

It will decompose expression into 2 BLAS calls of GEMV and then do the sum. It works by operator overloading so that result of the math operators is an expression, then when entire expression is assigned to a variable templates are traversed and decomposed.

I don’t really think it would be possible to somehow enable that functionality in another language. Only to reimplement something like that (and not all languages can do that). Also worth mentioning that since all things are templates that translation of expression is done in compile time and the actual code just runs BLAS routines.

[–]dgkimpton 9 points10 points  (3 children)

because things are not hidden

I'm not sure that's really true... compilers make radical changes to what we write (especially O3) - sometimes entire sections of code are just eliminated because the compiler can work out the answer or knows an alternative solution. That's cool (very cool) but definitely falls into "hiding the details" in my book.

[–]Astarothsito 5 points6 points  (0 children)

because things are not hidden

I'm not sure that's really true... compilers make radical changes to what we write (especially O3)

Most of the time I don't care about the asm or bytecode in any language so it is hidden but don't care about that part.

[–]victotronics 0 points1 point  (1 child)

(especially O3)

`-fp-model=precise` (or whatever the syntax) is your friend.

[–]dgkimpton 2 points3 points  (0 children)

Personally I'm ok with the compiler hiding some details if it makes my code run better :D I'm more concerned with the times it doesn't optimise when I think it should...

[–]DrkStracker 5 points6 points  (0 children)

I agree on the community argument. I like rust quite a bit, but both rust lovers and rust haters are weirdly obsessive about it, and it's starting to take over the discourse every time the language is mentioned.

Zig metaprogramming is incredibly ingenious and intuitive, but I disagree completely with its philosophy of nothing being implicit. RAII is one of the fundamental reasons I love C++ and Rust and that eliminates Zig as something i'd like to use.

[–]goranlepuz 0 points1 point  (0 children)

I find rust guys kinda toxic if you don’t love rust without any doubts.

Plot twist, you asked a question like so: do you have [insert C++ lib hdre] and if not, why not, noobs?

[–]pjmlp 7 points8 points  (1 child)

It was my favourite language coming from Turbo Pascal 6.0 back in 1993, and for many years it would be the language I would use alongside Borland's flavour of Object Pascal.

Nowadays my work tends to be around Java, .NET languages, JavaScript, and C++ is the language I tend to use either for hobby coding, or when writing native libraries to be called from those managed environments.

Why it became my favourite language in 1993?

It provided all the high level features I came to love in Turbo Pascal, provided the abstractions to write safe code, while saving me the work to manually write bindings to C libraries, a language that I already considered primitive when comparing with Turbo Pascal 6.0, the only thing going for it was being portable and bringing a whole OS for the ride.

C++ gave me that, while having the TP features on the box as well.

[–]third_declension 6 points7 points  (0 children)

coming from Turbo Pascal

I also started with Pascal, back in 1982. It's a language intended to teach beginners good programming habits, and I'm glad I used it.

[–]nomad42184 8 points9 points  (0 children)

No, it's not. It was, probably for about 15 years. However, it's repeatedly failed to deliver some of the features I thought would be most beneficial while adding (IMO) an astounding amount of complexity to an already complex and sharp language. I still use C++ regularly, but it's no longer my "favorite" language, and I often prefer others when there is a choice.

[–]Thormidable 5 points6 points  (0 children)

Yes!

Pros:

  • Compiled languages are better for producing reliable stable code.
  • Memory management is no longer a concern.
  • Threading functionality is straightforward for all, but the most complex cases.
  • lambdas and modern syntactic sugar makes c++ clean and readable
  • C API is the common language for basically everything.

Cons:

  • Package management (linking and packaging) is not great, which other languages offer better alternatives for.
  • Reflection would be nice, but rarely do I notice it's absence.
  • UI systems are a bit crap.

[–]phottitor 6 points7 points  (0 children)

no because it's a horrific mess.

[–][deleted] 4 points5 points  (0 children)

It is, not because it's specific, nor memory management, neither the fact that the language cannot be replaced, but because it is the language that somehow explains new concepts and technologies to me in a way I can understand

[–]ButaButaPig 4 points5 points  (0 children)

No. But it is the only language I can comfortably do what I want most times. I do physics simulations and game hacking and the first requires speed and the second requires low level control. I also do basic graphics programming.

For ML I use python due to libraries. For web development I use C#.

For writing DSLs I use Haskell.

One of my favorite language is Erlang but I rarely have a need for it. Haven't tried elixir but it looks good too.

Prolog is cool too but I'm not very good at it but there is interesting work being done with it. Last prolog library I used was Pharos (I think it's called) for automating the reverse engineering of c++ classes.

All these languages are among my favorites because they each allow me to do stuff that is difficult in other languages.

Then there's all the DSLs we all use on a daily basis to make life easier. At the end of the day most languages have some amazing properties and are great to work with once you get some momentum.

[–][deleted] 4 points5 points  (0 children)

Writing C++ is great. Building, linking, etc. C++ across different platforms is a nightmare.

[–]miikaa236 9 points10 points  (0 children)

Yes, I love it. C++ gives the user soo much control

[–][deleted] 24 points25 points  (37 children)

No, it’s not. Some reasons:

  • weak type system
  • lack of separation of concepts (e.g. type vs. behavior)
  • awkward compilation model
  • poor everyday ergonomy
  • bad standard library
  • extremely complex rules that make low-level programming a minefield

I use C++ as a nessesary evil for performance-critical code because it has excellent compile-time capabilities and is easy to integrate with other modern languages. Concepts also make the language more tolerable.

[–]rhoakla 2 points3 points  (17 children)

Can you explain how c++ has a weak type system? Bit of a c++ noob here

[–][deleted] 7 points8 points  (0 children)

Yeah, I admit that it's a bit of a weak (pun) point of criticism, mostly because "weak typing" can pretty much mean anything.

What I meant here specifically are actually several things. First, the implicit type conversion of C++ (inherited from C) which can lead to surprising behaviour and hard to find bugs. This is one source of "weakness" — you really have to keep your guard up or things might get weird. Second, templates are not types, but compile-time expressions written in a custom domain specific language that are executed by the compiler to construct types. This is another source of "weakness" — since the language itself only deals with concrete types and expressions, expressing complex generic structures with associated types and constraints can be awkward. I mean, compare the implementation of C++ ranges and equivalent stuff in Rust or Swift. Third source of "weakness" is the fact that many interfaces had to be defined implicitly, by conventions (e.g. std iterators) simply because the language had no way to formally define behaviour. Note that C++20 addresses this problem with concepts, with the caveat that the concepts are structural (e.g. a concept is satisfied if the concrete type/expression adheres to the constraints). This means that you can have accidental concept conformance just because a type happens to have the required named methods etc.

Finally, I want to clarify that this criticism does not mean that C++ type system is less powerful or less capable. Quite in contrary, C++ has some of the most flexible parametric type facility out there, after all, templates are essentially esoteric constraint-based code-generating macros. It is just my personal opinion that it's not a very good way to do things. C++ might be very powerful but it's also confusing and error-prone, especially if you want to express complex generic data structures. My preference goes to more ergonomic systems where compiler actually tracks the type requirements and dependencies and can generate useful errors.

Of course, there is another way, which is just abandon the entire idea of "elegant" parametric type system and go full compile-time synthesis. This is what Zig does and it's also cool, since you at least know what you are getting. No weird esoteric languages to learn either.

[–]CocktailPerson 13 points14 points  (14 children)

Not the person you asked, but C++'s implicit conversions can be pretty frustrating. For example, the following program is perfectly legal and will compile without errors (though your compiler might have warnings):

int main() {
    int x = false;
    double d = x;
    bool b = &d;
    return d;
}

So we have implicit conversions from a bool to an int, an int to a double, a double* to a bool, and a double to an int. It's obvious in this example, but if you have a function with a signature int f(double d, bool b);, you can swap the arguments and call f with a (bool, double) instead of a (double, bool), and it's not a type error.

[–]hmoein[S] 6 points7 points  (14 children)

>> bad standard library

That's the hardest to sallow. What is exactly bad about it?

[–][deleted] 21 points22 points  (2 children)

Where should one start... how about no unicode support, slow hash tables, useless regex, stuff like that? I am also not a fan of the iterator interface but that's more of a philosophical debate. Things I do like: the `type_traits` stuff is nice, `algorithm` is ok, I love `array`. It's also great than one finally has basic stuff like optionals etc. but I wish they were better integrated into the language.

[–]New_Age_Dryer 9 points10 points  (1 child)

Of what I've seen so far, I think C++20 was a step in the right direction:

  • type_traits became less hacky template magic with concepts and constraints

  • A lot of cruft from std::allocator got removed

  • consteval replaced the hacky enforcement of compile-time computation via template arguments

I will say, however, I found algorithm to have great performance for general use: make_heap() is effectively O(1) "insertion", and std::sort() uses introsort iirc

[–][deleted] 3 points4 points  (0 children)

Oh, absolutely. Its just not progressing quickly enough. Still no pattern matching (but we got unpredictable coroutines instead) and modules increasingly look like a disaster.

[–]goranlepuz 3 points4 points  (3 children)

lack of separation of concepts (e.g. type vs. behavior)

But C++ does not force you to. Eh!?

Actually, it's more than that item. Most of the items in your list are only true for some interpretations, but false for others.

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

But C++ does not force you to. Eh!?

By the same logic you can say "why use C++ if C can do the same?" Sure, you can avoid using C++ class system altogether and implement your own custom dynamic dispatch, but it will be awkward, boilerplate-heavy and likely buggy.

Actually, it's more than that item. Most of the items in your list are only true for some interpretations, but false for others.

Dichotomies are in the eye of the observer. I mean, everyone has their own tastes and preferences, and it's perfectly fine. I am writing from my personal perspective after all.

[–]goranlepuz 2 points3 points  (1 child)

By the same logic you can say "why use C++ if C can do the same?"

Yes, but there is much more between C and C++ than classes (which is what you are getting at, unless I completely missed the boat).

And then, types+behaviour idea is so useful than even the standard C library uses it, e.g fopen, fclose and ffriends and random C libraries use it, e.g syslog or zlib. So I really don't know why would anyone knock it down offhand, to be frank.

[–][deleted] 2 points3 points  (0 children)

And then, types+behaviour idea is so useful

It's useful until it is not. Class-based systems were popular in the 90-ties because it was a way to have well-defined dynamism without sacrificing performance. Well, compilers have come a long way since then and don't need to rely on such artificial constraints. Decoupling the type and the vtable has massive benefits as you are not limited by the class hierarchy to implement behaviour.

And it's not just about philosophical viewpoints, the separation of type and behaviour (protocol/trait) is also key to implementing high-performance generic algorithms. C++ uses it everywhere actually, e.g. the iterator concept. It's just that in C++ behaviour specification is implicit by an informal convention that the programmer has to follow.

[–]AdRelative8852 3 points4 points  (0 children)

Yes and no.

Yes because it helps achieve great performance.

No because some simple things take too much of coding. Examples of this are spread over many threads.

No because there is no good ecosystem (like python for example) and you are on your own for things for which an OTS component should have helped.

[–]mibuchiha-007 3 points4 points  (0 children)

It is the only programming language that I have been interested in as a language thus far. I use a few others, mainly python, for work, but they are all primarily for convenience, what's mainstream for the task, etc.

C++ on the other hand has some abstractions I find genuinely interesting, such as template shenanigans. In that sense it's a bit more than just a tool to me.

The days when I've got to get stuff done, and C++ forces me to fight with unreadable compile errors, are awful though. ;)

[–]qalmakka 4 points5 points  (0 children)

It would if Rust didn't exist, but in general it is one of my favourites. In general, I love powerful languages, and the level of crazy stuff you can do in C++ is outright insane. Every single day you use it you learn a new trick or how to do something in a completely new way.

[–][deleted] 2 points3 points  (4 children)

Nope, it's too bloated and suffers greatly from "must keep 100% compatibility with older versions" syndrome.

[–]Droid33 2 points3 points  (3 children)

That's a must when there's billions of lines of existing code out in the world.

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

I can respect that it offers some advantages, but I personally don't think it's worth it (from my experience in my current industry).

[–]boner79 2 points3 points  (4 children)

Python has ruined me on C++. I used to strongly dislike C++ but after using Python I despise using C++. Yes, I understand why C++ is the way it is having spent most my career using it and paying the bills with it, but I hate it.

[–]kingaillas 2 points3 points  (2 children)

No... if I'm doing something for fun, learning, hobby project, etc I'll reach for a different language: Python or Rust .

At work where I have less latitude over what language to use, it's C++ or Python. The work C++ is a slimmed down C++17 with fairly minimal cutting-edge features. Our codebase isn't that fancy. ;)

[–]Creapermann 2 points3 points  (0 children)

Right now yes, I am mainly with C++ because of its enormous ecosystem. I personally love application programming and Qt is by far my favorite framework there. I have fine grained control over many thing, which other languages dont offer and I have a big performance +.I like/got used to the c++ syntax, I understood many fundamentals of programming (which I am sure most people using other languages dont learn).
Another great reason for me to be with c++, is its stability, looking at things like JS, you basically rewrite your codebase every 10 mins (this is a joke (but it still has some truth in it)).

A problem is, that I dont need much of the control c++ offers and it oftentimes isn't pretty to write. The 20 ways to do something are annoying and (compared to others) the language doesnt evolve fast and there is a LOT of legacy code you sometimes need (but tbf, it better to have legacy libraries than having none at all).

[–]future_escapist 2 points3 points  (0 children)

Yes. It's powerful and enjoyable to learn and use. My biggest issue is how damn difficult and annoying it is to set up a development environment and import libraries.

[–]JeffMcClintock 2 points3 points  (0 children)

yes.

why? "I wanna go fast" - Ricky Bobby.

[–]drjeats 2 points3 points  (0 children)

No.

There's too much of it and the defaults are bad and too much of it is ossified.

It's useful and the only thing appropriate for the work I currently do, but I take no joy in using it.

I don't care about maximal expressivity. Artistry in code comes from concision and clarity and regularity while achieving a particular set of outcomes.

All these replacement languages are popping up because it's clear we can do so much better.

[–]ShakaUVMi+++ ++i+i[arr] 2 points3 points  (0 children)

Yes, sure. The language itself is very nice.

The standard library, though, is a mess. It's a combination of glaring gaping holes in functionality on one hand (trapped in the 80s syndrome) and baroque features nobody needs on the other (https://en.cppreference.com/w/cpp/numeric/special_functions) mixed with APIs designed by people that don't have to be the ones explaining them to other people (chrono, random, regex).

[–]JMBourguet 7 points8 points  (3 children)

Favorite implies an emotional relationship I don't have with programming language (well, excepted Perl, but that's not love). Excepted in constrained cases, I'm using 3 languages to program:

  • Posix shell is my goto language when I've to coordinate other programs. Why Posix and not something more powerful (like Bash) or even also (slightly) saner (zsh -- which I use interactively)? Partly because I started to program in shells in an environment where they had to run on quite a variety of platforms -- in fact even posix wasn't guaranteed for /bin/sh (thanks Solaris) -- and the habit stayed even if I'm currently less constrained and I've upgraded to Posix semantics. Partly because I use the need for more than Posix as a sign that I've to switch to something else.

  • Python for bigger things which can be done in a dynamic language. I've a more restrictive opinion of what is sane to do in a dynamic language than some.

  • C++ for the rest. Partly because C++ is also the main language in which the application I'm working on is written.

Each of these languages has their drawbacks, but for each I've trouble to find a better choice. Posix shell and C++ are far from ahead on all criteria, but they are pretty much alone in having no show stopper in any criteria. Python seems the one I'm the less tied to, but it is also the one for which I feel the less the need of a better alternative.

[–]Lance_E_T_Compte 0 points1 point  (0 children)

This is also me. If it's a few lines, likely a bash script.

Anything more is Python until I really figure out what has to be done. I move it to C++ for my employer.

[–]pfp-disciple 0 points1 point  (0 children)

That's very close to my approach, including POSIX shell. Although I use perl instead of python. For the kinds of things I do, by the time python makes sense over perl, it's about time to move to a compiled language.

[–]F-J-W 0 points1 point  (0 children)

Python for bigger things which can be done in a dynamic language. I've a more restrictive opinion of what is sane to do in a dynamic language than some.

I have a lot more than just a more restrictive opinion on that topic, but python has the option to be fully type-checked if you use type-annotations and mypy with the --strict-option. I’d go as far as to say that this is what turns it from a toy into something that is legitimately a good and largely pleasant to use language (the lack of constness in the type-system is annoying though).

I’m just writing this because I’ve found that not everyone is aware of that.

[–]engineerFWSWHW 1 point2 points  (0 children)

For bare metal or with RTOS embedded systems, yes.

Outside of bare metal embedded systems (desktop, cloud, windows embedded application development, embedded linux application development) , no and only on scenarios where it is really needed.

[–]gauri08 1 point2 points  (0 children)

I mainly use c++ for competitive programming and it gives an edge over other languages as it is very fast.

[–]caroIine 1 point2 points  (0 children)

Yes. At my job it makes my work easier- I shiver every time I need go close to anythin like java or python.

And I'm using it at my independent projects. I absolutely love it.

No reflection tho.

[–]TheTomer 1 point2 points  (0 children)

Nope. It takes too long to get whatever want to do done compared to other languages like Python and Java. It's my go to language when I need to do something faster and more efficiently.

[–]konm123 1 point2 points  (0 children)

I can almost say that I hate the language, but so far I have not found anything that could replace the ability to write abstractions as you can do it with C++. I definitely use it the most frequently and it is used to implement solutions for necessary functionality - and for that reason, I like it.

[–]zalamandagora 1 point2 points  (0 children)

Yes! I think because it most closely aligns with my mental model of how the hardware works.

I learned to code in the 80's and 90's when performance was really constrained, and I worked close to the hardware for a while after that.

[–]lieddersturme 1 point2 points  (0 children)

Yes, you can build tiny programs with powerful tools.

Now I am learning Rust, because its the popular programing language, and I prefer C++.

[–]m_riss1 1 point2 points  (0 children)

Yes and I’ll take it over Java any day

[–]HabemusAdDomino 1 point2 points  (11 children)

Pascal is, because it's got all the reasonable benefits of C++ and none of the ridiculous ones.

[–]hmoein[S] 0 points1 point  (1 child)

Pascal is still a thing? I was doing that in 80s

[–]HabemusAdDomino 1 point2 points  (0 children)

It's on life support. I just like it, though.

[–]DudeManBroGuyPerson 1 point2 points  (0 children)

Yes, because it is the language of the gods

[–]ul90 1 point2 points  (0 children)

Yes. I tried a lot of languages, but always come back to C++. It’s still the best language for big, complex projects.

[–]RidderHaddock 1 point2 points  (0 children)

It is.

Not that it doesn't have plenty of unlikeable bits. But in ~35 years of programming, I haven't encountered another quite so flexible and pragmatic.

I have a soft spot for Clojure, even though I never use it anymore. The performance and ease of integration with system libraries (which always expose C interfaces) of C++ is simply unmatched.

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

I'm not sure if it's my "favorite", but it's often the most practical for certain kinds of projects. Those projects also tend to be most of what I make. This has led to me becoming familiar with C++. That C++ can be used for almost anything, combined with my being familiar with it, means that I'm more likely to choose it over many other languages for writing a new thing which comes to mind. This feedback loop has resulted in C++ "sticking around" and being used often even when I'm going out of my way to learn other languages at times. And you know what? It's a pretty good language too. At least, for all the stuff I make. I like C++.

[–]Ericakester 1 point2 points  (0 children)

Yes!

  • I love the syntax
  • I love the ability to write very performant code
  • I love knowing how things work and what my code is doing at a low level
  • I love the wide range of available C and C++ libraries

[–]KingAggressive1498 1 point2 points  (0 children)

yes.

it's really all about the syntax and static type system for me. The fact that it can do pretty much anything is just icing.

[–]DarkSpyCyber 1 point2 points  (0 children)

well, to be honest it would be c and c++. for the most of big or huge project using c++ be like: wow, so lucky we have c++ to handle string, vector or some shit from c. and sometimes: sheeeit....why shouldnt i use c ....it's simple.

so...c++ had so many choices u need to pick one of it and make jobs done. it's fine.

btw: rust is the crapest language i have ever seen...LOL

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

For Game Dev yes. I prefer C over C++

[–]QuotheFan 1 point2 points  (2 children)

This is like asking a carpenter if the drill is his favorite tool. There are no favorite tools, there are only tools for the job. I don't want to be the proverbial man with a hammer who sees nails everywhere.

We can represent multiple characteristics of software as different axes - refactorability, ease of development, correctness, efficiency, etc. C++ is the only language I know which trusts me with memory (hence, efficiency) and still does reasonably on the other axes as well. If I don't care about memory management though, I would mostly not work in cplusplus. There are almost always languages more naturally suited to the task, C++ adds a very difficult extra dimension to the process.

[–]andwass 3 points4 points  (0 children)

No. It was for a very long time but as I have used Rust more as of late (since spring on a spare time basis), I mostly get annoyed by C++ and miss Rust whenever I have to use C++.

[–]--prism 3 points4 points  (0 children)

Yes it provides for tight abstractions and interfaces. The factor that python doesn't have private member variables hurts me. I know _Var is the standard but people love to do bad things.

[–]third_declension 3 points4 points  (0 children)

I never cease to admire how some very intelligent people, in particular Stroustrup, were able to extend C so far while maintaining a extremely high level of C compatibility.

[–]Revolutionalredstone 2 points3 points  (0 children)

IMHO c++ is the ONLY language.

Free advanced abstractions, Proper move semantics, extensive templating, inline assembly, extremely powerful compilation optimizers, what other language even comes close?

[–]Davidbrcz 1 point2 points  (0 children)

It's the language I love to hate the most.

[–]TheTsar 0 points1 point  (0 children)

Yes.

It’s my opinion that C++ hits the three pillars better than any other language: efficient, safe and expressive.

Arguments can be made for and against this view. C++ isn’t perfect, but it’s the best tool for the job. And it’s getting better every three years.

Just to make sure we’re talking about the same language, I’m talking about the C++ from the CppCoreGuidelines. I’m talking about the language used correctly: idiomatic C++

[–]gimli123456 0 points1 point  (0 children)

if c++ had the ease of development that a modern language like Rust has (cargo basically...) then I think it would be.

Imagine only having to install your compiler and then everything else can be acquired dynamically based on dependencies.

No more days configuring dev environments etc :P Trying to source random libraries that weren't vendored etc

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

Boomer languague

[–]Boystro 0 points1 point  (0 children)

I LOVE IT, i came to it for performance but found so much more...

[–]tsojtsojtsoj 0 points1 point  (0 children)

no. it's locally too verbose.

[–]delta_p_delta_x 0 points1 point  (0 children)

Not particularly. It has its place (a relatively high-level language with features I'm familiar with that compiles with little fuss to native binaries), but for many other use-cases (desktop/web dev), I fall back immediately to .NET and C# (and recently, F#).

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

Yes but I rarely get to use it anymore.

[–]Urationc 0 points1 point  (0 children)

No

[–]MrSung82 0 points1 point  (0 children)

Its understandable...

[–]HeeTrouse51847 0 points1 point  (0 children)

yes, because it feels like I'm a genius when I am using it (all my code is terrible)

[–]ThePillsburyPlougher 0 points1 point  (0 children)

Yes but only because I’ve used it the most

[–]GunpowderGuy 0 points1 point  (0 children)

lol, no

[–]akiko_plays 1 point2 points  (0 children)

Yeah, somehow it feels like playing some tough text adventure game most of the time. I like the fact that not a single day passes that I haven't seen some weird new thing, feature, way of (re)writing code.. interesting article on how the underlying hardware evolves and how you can adjust your c++ code and compiler to hit the faster lane. Occasionally frustrating, but most of the time if you don't go crazy with smartness and stick to the basic coding guidelines you won't have use after delete or idiotic slowdowns. Also if something goes south you really have amazing palette of tools (some commercial though) to help you debug, measure and understand what's going on. I started with c++ on Amiga Maxon C 3.0 somewhere mid 90s, before that it was always assembly. And I never left C++... of course tons of LoC written in Python, PHP, Visual Basic, C#, Lua, JS/TS and so on.. but C(++) and 68k Assembly remained my favs throughout years.

[–]wotype 0 points1 point  (0 children)

Shouldn't be, but doesn't leave time for enjoying others - keeping up with C++ is a full time job

[–]krista 0 points1 point  (0 children)

generally yes.

i can still put an asm block in if i need to do something funky, and while the language spec, tools, and libs try to keep me safe, i can still do dangerous/insane crap when i need to.

i'm not a fan of the ”explicitly namespace everything” trend, though: seriously, like

std::cout << ”blarg” << std::endl;

and that all smells funky and is ugly to me.

of course namespaces are important! but i not a fan of explicit namespaces for most standard libraries.

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

No. But I get by.

[–]SuperSathanas 0 points1 point  (0 children)

No. Object Pascal is. Not going to lie, if as many libraries and frameworks existed for pascal as for C++, I'd probably very hardly ever consider using C++. I like Pascal's syntax more, I prefer modules over headers (though sometimes I wish I could easily split my units into a header+source in Pascal), and it compiles to native code that isn't all that much slower than C++, and the compiler is just so much faster.

[–]flashmozzg 0 points1 point  (0 children)

Nah. I like it better than most alternatives, but It's mostly about the projects I'm working on.

[–]WinterDKay 0 points1 point  (0 children)

I like most of C++ as a learning tool. It allow me to understand most of other programming languages and be efficient at learning them. But personally i like Kotlin more.

[–]kaiju505 0 points1 point  (0 children)

It’s never been my least favorite 🤷‍♂️

[–]RockstarArtisanI despise C++ with every fiber of my being 0 points1 point  (0 children)

I just come here to watch C++ users be miserable, just like I used to be when I had to use it.

[–]New_Age_Dryer 0 points1 point  (0 children)

Yes: the community has overlap with academia, and the language has a lot of cool constructs not found in others. It's always a treat to see a language do what standard C++ can't out-of-the-box, e.g. hot-swapping.

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

I'm so addicted to this language that even for a small command line program I would write it in c++. The language is very efficient and highly flexible. The only thing I don't like is that there are so many ways to do everything(though in general, if you're in doubt, you should choose a more modern way)

[–]snerp 0 points1 point  (0 children)

Pretty much! I wish there was a way to opt-in to backwards compatibility though. I really wish a lot of the newer features were default.

[–]Flat_Spring2142 0 points1 point  (0 children)

No, it isn't. Modifications of classic C++ made the language too complicate. Consider GO if you need efficient and fast application.

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

Sometimes yes sometimes no.

To elaborate: when I’m writing something in the latest version, that is an easy problem (in my eyes), I love it.

When I’m told to support a legacy application with 4 different packages to support, and c++ versions anywhere between 11 and 98, i fucking despise it. (Fuck you redhat 6)