๐ A Hex Editor for Reverse Engineers, Programmers and people who value their retinas when working at 3 AM. - WerWolv/ImHex
I've been trying to learn a system language because it would enable me to access a whole new world of possibility for games, tools, and potential projects. My main problem when learning the language are:
can I write modern C++ code using the newer standards and still compile with libraries from older standards?
how do I even organize a C++ project? Look at the linked project, the CMakeList.txt is so hard to understand, the syntax looks so hard to write.
how do I install dependencies? You're going to laugh at me, but I always used languages with package managers and I looked again at the linked project, and they write a whole CMakeList.txt to import ImGui (GUI library I wanna try) but if you compare the structure of the files, it's different from the ones on the repository of ImGui.
As you see there are a lot of problems and it pains me to not be able to solve them because Rust is so unfun to use and work with! Do you think I should try C++, carry one with it?
C++ is a great language. However, the standard library is small and the systems for package management are vastly inferior to what you find with other popular languages.
C++ applications regularly use largely organization internal code bases with bits and pieces of the standard library integrated into them.
That's so as to say, with C++ code tends to be more freestanding/independent but it also means that the time from no code to "working" for non-toy projects is way higher than it otherwise should be (e.g. if you could just trivially pull in a few good libraries).
can I write modern C++ code using the newer standards and still compile with libraries from older standards?
The answer as to "can you take C++11 code and mix it with C++20 code" (as an example) is a more complicated one. I suggest this excellent answer from Jonathan Wakely which is relevant to the GNU/GCC C++ implementation https://stackoverflow.com/a/49119902
how do I even organize a C++ project?
This is something I struggled with when I first came to C++ land and the answer is basically "however the heck you want."
Every C++ project takes a different approach. C++ build systems are closer to bash script anarchy than some carefully crafted standard practice.
If you go into C++ build systems expecting well established, consistent, conventions... You're going to be disappointed and frustrated.
The C++ ecosystem in general provides options more than answers. This is in contrast to something like Ruby on Rails where convention over configuration is the mantra.
Do you think I should try C++, carry one with it?
If you're interested, absolutely! You do need to temper your expectations with C++ though. It's a great language once your code base has some momentum, prior to that point though you're going to have to be scrappy.
I'd recommend trying to either expand on an existing project or working within an established ecosystem that does have some guiding principles. Qt, CryEngine, Godot, Boost, CMake, and Meson are all terms I would Google and consider looking at to varying degrees. There's also cool stuff to look at here: https://en.cppreference.com/w/cpp/links/libs
C++ is great with many things, but a consistent build system is Definitely not one of them. Additionally to note, when doing CMake stuff, it's generally best to stick to the modern way of doing things (targets, rather than a slew of global properties); it ends up being a lot easier to develop as projects grow and other dependencies are added.
I have over a decade of professional C++ experience.
Most of my fellow developers are still wrapping their heads around C++11.
I've never used cmake and have no idea how, it's always been something custom or something generated by an IDE (usually VS, not vscode, I'm talking about the gigantic purple monster).
Download source or even binaries and check 'em in. I had never even heard of package management until I started working with other languages more.
Some of these situations are probably better outside of my industry (gamedev).
That's odd. CMake is the de facto standard in C++. Even Visual Studio supports CMake, and perhaps the best IDE for C++, CLion, is basically built around CMake.
What exactly have you been doing in that decade of experience working with C++?
Like I said, game development. For example, I know Unreal's build system pretty well and that's a bunch of batch files, C#, and nmake that gets generated automatically.
Not the OP but I've had the same experience. For me, it's slow to iterate in due to fightting the compiler. Languages like Go, Python, Java, C are all quicker to develop in, IMO.
Exactly, youโre right: it does not feel like youโre creating? Youโre always fighting against the compiler and I prefer some debugging/seeking and keeping good practices that being surveilled and punished by the compiler.
can I write modern C++ code using the newer standards and still compile with libraries from older standards?
Yes, but then your project ends up requiring that newer standard as minimum too (which can be fine if that's what you want).
how do I even organize a C++ project?
Well, one way that should be simple and scalable for beginners is leaving the root folder for project configuration/metadata/contribution guidelines/clang-format etc. and putting all source code inside src/.
If it's just an app, you can make smaller library targets in src/ in separate folders with meaningful names, like src/models/, src/settings/ etc. If it's a library, you typically put headers you intend to expose to your users in a src/include/ folder and use target_include_directories() to point to it, otherwise the same principle as apps applies.
It requires writing a few more, smaller CMakeLists, but it does mean you're never lost in your own code.
can I write modern C++ code using the newer standards and still compile with libraries from older standards?
Short answer: yes.
Longer version: It depends on what compiler suite you're using. In the end the main requirements are that a) include headers are valid C++ in any of the standards you're targeting (i.e., don't expect to build a C++11 project which includes language features introduced in C++20) b) it generates symbols that can be resolved and linked on all binaries.
This should be done as a last resort, though. The problems you might experience won't be trivial to troubleshoot or common.
how do I even organize a C++ project?
One of the main advantages of C++ is that it does not enforce any project tree layout. It doesn't even require a specific file type or file extension. You are free to follow what works best for you.
If you want a guideline, that can also be provided. See for example this link:
Wtf? How is rust unfun? Rust is by far the best language to write. Try not using references at first, just clone. Then you don't have to worry about the borrow checker.
Honestly if you think rust is unfun I can't imagine you'll get along with c++
The Rusty community itself stated in no uncertain terms that even they believe Rust is already too complex, and the numbers of those expressing that concern are growing every year.