5 ms·
I've been using C++ for around 20 years now. I've spent a lot of time learning the language, although I don't know any of C++20 yet. The issue with C++ is that
by jack_h 4y ago
I've been using C++ for around 20 years now. I've spent a lot of time learning the language, although I don't know any of C++20 yet.
The issue with C++ is that the 'proper' way to do something almost always requires an encyclopedic knowledge of the language; any other solution you come up with will likely be wrong or at the very least suboptimal for esoteric reasons. It's not that people aren't smart enough, it's that there's not enough time to really learn the language. I know I've sacrificed sleep and social life just doing deep dives into the language to really understand it. The reason I don't know C++20 yet is because I'm not willing to make those personal sacrifices anymore, and even if we could use C++20 where I work we don't have infinite time to learn it before being productive.
- gabereiser 4y agoThis. That encyclopedic knowledge of gotcha’s and work arounds and such is why people hate C++ so much. It’s far beyond tolerable. If you were to restrict everything to just c++20 (force shard_ptr, etc) it would still be something only battle hardened adventurers would pursue. Languages like Go and Nim and the all mighty Rust try to take away complexity for a bit of convention and provide safety for us mortals that just want to get an idea across. For those that are weathering the storm in C++, I commend you, but you’re going to need therapy. (joke but the effects of stress are real).
- synergy20 4y agoI somehow feel Rust is even more complex than C++ For C++ I settle down with c++17|c++20 and they're still complex, but not that bad though. Go might be simpler but C++ can do whatever Go does and I tried to master both, it did not work, so I had to pick one and that one has to be c++ for my use cases.
- gabereiser 4y agoGetting around Rust’s syntax is pretty much the whole battle.
- 3836293648 4y agoAnd the borrow checker
- tialaramex 4y agoHopefully, if you are transitioning from writing C++ to Rust the basic ideas the borrow checker is enforcing feel pretty familiar. Shared mutable references and references which outlive the thing borrowed are bad ideas in C++ too. You should avoid them, and be careful to use a safe pattern to handle them when/if they become necessary, Rust just has the compiler looking over your shoulder instead of an implausibly good code reviewer.
- pjmlp 4y agoRc<RefCell<>> and .clone() calls everywhere for most GUI applications.
- ChadNauseam 4y agoIs Rust syntax really that different? I've only written a little C++, but it seems pretty similar to me. They mostly just switched from `type x = ...` to `let x: type = ...` and let you return stuff by putting an expression at the end of a block, right?
- gabereiser 4y agoWait until you need a heap allocated resource counted mutex. Or have a struct that out lives it’s creator. &mut Arc<Mutex<Option<Box<MyStruct>>>>
- tialaramex 4y agoRight, but while that's a bunch of stuff the syntax here isn't intimidating. It's a mutable reference to an Arc of a Mutex of an Option of a Box of MyStruct. You presumably could build yourself one of these in C++ although since the standard mutex in C++ can't actually protect anything (you're supposed to just remember to lock it anywhere you need to, you know, because C++ is a language for people who never make mistakes) you would need to build that part yourself. And if you did build that yourself in C++ the syntax for the type would look rather similar, although I guess C++ allows you to just say auto meaning, "I dunno, guess" for the return type in a function signature whereas Rust insists you must actually write return types and don't leave them for the compiler to figure out.
- kllrnohj 4y ago> For those that are weathering the storm in C++, I commend you, but you’re going to need therapy. (joke but the effects of stress are real). Every new release of C++ tends to reduce, not increase, my stress. Many of these patterns, including this one, just largely stop being things entirely. Rule of zero and all that.
- jandrewrogers 4y agoC++17 and especially C++20 are reasonable programming languages that you rarely have to fight or work around. Things have become much simpler. Anything prior to C++11 was sufficiently awful to work in that I used other languages. They really resurrected the language with C++11. It can be messy, because backward compatibility, but a lot of newer code bases start time with idiomatic C++17. The standard library is the primary place you'll still run into old style C++.
- pjmlp 4y agoI would love to see one such code base, that isn't my own hobby coding. The libraries we get to plug into our infrastructures show another reality. Or in a better way, see the usual talks about the state of teaching C++, and the quixotic endevours to improve it.