5 ms·
This. 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 every
by gabereiser 4y ago
This. 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.
- gabereiser 4y agoAnd in Go, it's inferred and you don't have to bother repeating yourself.
- tialaramex 4y agoRust deliberately chooses not to infer the return type in a function signature. Inferring return types is convenient for the person writing the function, but adds cognitive overhead for people using the function and makes it easier to introduce incompatible changes without realising (the signature you wrote is unchanged but a different signature is now inferred)
- 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.