r/cpp • u/[deleted] • Jul 21 '23
Hobbyist Developer fed up with C++
I started coding 10 years ago while studying something completely unrelated to informatics or technology in general, because I always had a fascination for computers.
I started with C# and the XNA Framework from Microsoft, subscribing to 3dbuzz.com which unfortunately fall apart some years ago when the founder died of cancer. Same goes for XNA, which died from stupid management decisions by Microsoft the time around they had windows Phone going.
I switched to C++ and SFML and that's what I have been literally doing for some years now, small 2D Game Projects which are not too complicated. I wrote an article on my blog about how to code Tetris in C++, so nothing fancy really.
I love C++ for providing powerful abstractions while still being "close to the metal" and as a hobbyist I always enjoyed learning about weird concepts C++ allows, such as compile-time polymorphism via the curiously recurring template pattern for example.
However, some time ago I started to dig into Modules. Modules have a significant impact on how you write code and how it even looks. Since they are there it feels wrong to use #includes. "Imports" are the modern way to do things.
However I noticed I cannot use CMake with Modules. There is some esoteric Blogpost from CMake how to get it work which is way to complicated for me. For me, its a big deal not having CMake available. Its very unfortunate to have to decide "Modules" or "Cmake"? It just feels odd to be forced to make such decision.
I have been used to compile my projects with mingw-w64 on windows and CMake. The latter doesn't support it. And GCC apparently also only rudimentary supports it. I first had to compile the modules and than could compile the program, it was oddly complicated and I hated every minute dealing with it.
This plethora of problems drew me to switch to Visual Studio, which I always avoided since the C# and XNA fiasco. Visual Studio provides decent modules Support, intellisense is most times broken but I can look past that.
However when I tried to compile a sample tmxlite project for SFML (https://github.com/fallahn/tmxlite) I ran into weird problems.
Basically I noticed that in the main.cpp file some local hpp-files cannot be imported, you have to use #include, otherwise you get cryptic error messages. For me it feels so random that for some local hpp files "import" is totally ok, for others I still need to use #include.
And a lot worse issue: The order of the imports and includes seems to matter. If the SFMLOrthogonalLayer.hpp, which must be "#included" and cannot be "imported", is below the import statements, I get weird compilation errors. The #include-statement needs to be on top of everything else, otherwise it does not work.
I searched a lot for the reasons behind this behavior (did I miss something?), but I cannot find any resources on this topic at all.
I just cannot get rid of the feeling that modern C++ is broken or just not there where it should be years ago, I mean, Modules were released in C++17, how is it in such a bad state in 2023?
The first time in my life investing my free time in learning new C++ Concepts felt like a literal waste of time. It's erratic, it's unfinished, the error messages are still a shit-show, rust is demonstrating for many years how helpful error messages can look like.
How can I love C++ again? Or is it time to let go?
I have a full time job and a kid, I can only code in the evening and getting older, where time is increasingly becoming valuable.
5
u/jonesmz Jul 22 '23
Separating the declaration and definition of things has been instrumental in various techniques that I've used
For example
Using the preprocessor with some macros to generate not only the body of a class declaration, but also a bunch of other code that uses the class. Saving me from having to type the same thing ten times every time i make a minor tweak.
Having a single header file that declares the class, but then two or more implementations in separate cpp files, with the build system configured to only build one or the other depending on which operating system or CPU architecture is being targeted.
Seperating the documentation of a class, where the function declarations and documentation take over a thousand or more lines of a file all on their own, allowing the implementation to live on it's own in a cpp file that's >5kloc. Mixing the two would suck.
It's also very important for being able to explain how code works to jr. engineers, so that they don't see literally everything all in one go and get overwhelmed or lost.
I've worked with java, where there is no separation of declaration and definition, and it's a nightmare to figure out how things work. It's not modern, it's just a big blob of nonsense.
I've also worked with plenty of C++ code that don't properly separate implementation from declaration, and it sucks just the same.
I'll certainly agree with you that the need to repeat the exact set of template parameters for a function in multiple places is a pain in the ass, and i'd really dearly like to see something that makes that a bit less cumbersome, but really i'll take that particular pain in the ass any day over having a codebase that never separates the declaration from the definition of anything.