by photochemsyn · 3y ago · 0 comments
Troubleshooting a big legacy C++ codebase is probably something that Dante would have included in his Inferno as a punishment for pride and hubris.
Uh, but it still kinda sucks, if only because the nice way that looks idiomatic is usually the incorrect way for either performance (anything newly added like std::variant or std::optional) or safety (operator[]).
The correct way is usual the ugly way, because it seems like the committee puts C++ arcanum knowledge above all else, instead of developer satisfaction or maintainability
At least the C++ compiler is doing actual work. And it is faster than the webpack madness.
I don't know where you got that idea from, but with an up-to-date compiler variants are safer and more performant than the traditional approach (classes hierarchies), and std::optional is safer and 99.9% as performant as a nullable pointer.
Except for it taking up twice the memory as a pointer (https://godbolt.org/z/5We9zEbvh) and it not doing anything in regards to safety when using pointers. Even if you're replacing a nullable-pointer with a std::optional you're still handling landmines when using operator* or operator-> - the most convenient ways to use std::optional.
C++ is doomed forever to have safety-third design.
A modern project should be able to use most of C++17 at least. Even if you still need to target some ancient garbage like Windows XP, you can use an MSVC toolchain that supports C++17. That's a good basis to work from.
So your real concern is the moldy old code that's written for C++03, that's still not using std::unique_ptr or anything equivalent. If you're given license to finally rewrite that code to modern standards, that can be fun if it's not a complete mess. But if you just have to live with it, and still write C++03, absolutely not, I would never do that job.
But that's mostly learning modern paradigms of the language.
If you also mean the tooling, then it depends: Learn CMake which is sort of an industry standard. There are books and videos, but for a concrete experience, try looking through the CMakeLists.txt of some non-trivial C++ open source project.
Probably the best resource for CMake modern best practices/ rational of those practices.
Most tutorials online are outdated, CMake documentation is hard without a firm mental model of how it works.
You say that like there's one for a project but I've been learning Blender's codebase and every folder has a CMakeLists.txt. What gives?
Use clangd, clang-tidy, cppcheck. (These will tell at you if not using best practices)
Use the stl as much as possible (or at least make "would this work using stl" your go-to question.
Write a vector with iterators from scratch in c++20
Then you aren't choosing C++20-something, you're choosing a new language altogether.
This is why the demand for C++ devs is dropping - if you're going to bite the bullet and rewrite, why not choose a better language, preferably with GC?
It's not like C++20 is completely different. There's just a lot more utilities in the stdlib so hopefully less raw pointer magic.
What was best practice for C++03 is not the same for C++20.
Switching a codebase from C++03 to C++20 for a nontrivial codebase means changing design so radically it may as well be a new project, rewritten from scratch.
It'd certainly be easier to rewrite in C++20 for the C++03 projects I've recently worked on, than to try to squash in a C++20 design.
... with deadlines measured in hours.
I spent two months asking one guy who knew about it for help. I really understood the concept of "hostage taker" in a software team. It's the guy you cannot fire and will constantly arm-wrestle everybody where there is a problem, never really helping, and continuing to write bad code that allows him to keep his job.
Fortunately they did not hire me.
I never was so discouraged in my life.
I don't understand this, where you working for free?
This is, obviously, a very opinionated opinion.
If I was going to be forced to do it, this is how I'd want to do it.
I write software in probably a dozen languages, including C++, and using the features/STL in C++17/C++20 in no way makes using C++ a "pleasure", it simply makes using C++ "less painful".
If I want to present information processing applications to users, it's C#/Java (or Kotlin, or Scala, or F#) with some Typescript front-end and likely some form of SQL simply because those are the tools that enable me to accomplish the job the fastest with the highest quality. If I need software to work in or with embedded systems then I grab C simply because it's the tool that enables me to accomplish the job the fastest with the highest quality. If I need some software to bridge those two worlds then I reach for C++ because it's the only tool that efficiently bridges the gap.
And C++ sucks, even with C++17/C++20/STL because I can't tell from the STL documentation which pieces manage memory for me and which I have to remove on my own and when this memory management (sometimes) magically occurs. I know what it is with C, because it's all malloc()/free(), and I know what it is with JVM/C#, because it's managed for me, but with C++ it's an incomprehensible mess. Don't even get me started on the half-assed implementation of lambdas vs. function pointers vs. std::function and which can be used where and where the const/reference operators have to go.
Modern "pleasant" C++ is a subset of all of C++. In the realm of all C++, you can get into some REALLY bad code. That includes terse C.
I work in the NYC market, and have bounced between finance and tech. The quality of C++ at a tech company, even legacy code, is magnitudes better than the stuff in finance.
I’m lucky ;)
If you care about it, it can and will be done. Same, all warnings enabled, compiles and runs in both AMD and ARM processors, it is just 20 to 40 times faster than the thing it replaced, I really can't complain.
C++ gets underserved hate by people who don't care about doing a good job anyway.
C++ today is like Cobol in 2010. yes, there are reasons for them to exist, people tell your the good old days, probably some fresh good recent experience. but come on, there is a much better place for C++ -
Gaming has Unreal but surely you could use another game engine without C++?
We release the same plugins on Windows, macOS and iOS so we get great coverage with compilers too. I should set up a build for Linux with gcc but haven’t had the time yet.
I may have exaggerated with the “nearly every” sorry!
But we do use sufficiently enough tools to avoid most of the pain of c++
C++ has wide use, and will continue to have huge use, for both old, current, and new codebases, in tons of areas, from systems, finance, and OS, to scientific and games.
you know people collect old cars, computers, stamps as hobby, tens of millions of people are into that. for the exact same reason, there will be people who are just into writing software using legacy tools. I totally understand & respect such decisions.
Almost in every case, you'll find C++ at the core of them.
Last couple jobs have been heavily legacy C++ in the energy sector.
Lots of maintenance, but also opportunities to overhaul and build new objects.
Funnest project right now is porting some supercool Science code to cuda and getting about a 30x speed up.