DEV Community

Vincenzo
Vincenzo

Posted on

Back into C++ in 2021: First Week

as I said in the previous post, I have been re-learning C++, after a decade of not touching it at all and having only coded in many other languages.

In that post I asked some questions to try to find a link between tooling that I have been using in other programming languages, coding standards and environment setup and what C++ provides in 2021.

This is what I found after 1 week:

C++ looks and feels amazing.

I had forgotten how cool it feels to code with it, and with all the new tools that the standard library provides, it definitely is not that hard to approach thing I studied at University ages ago.

std::async, (Example:) god it feels good to do multithreading in C++, and it is as easy as any other modern language.

Smart pointers are amazing, and it makes managing memory a breeze, and easy to read track down.

Algorithm or You dont need to copy paste your shitty implementation of bubble sort, str_reverse or whatever else to do basic stuff, it is all in the language, why no one had told me that at Uni? :D

C++ people are obsessed with performance

Normal humans dont mind too much to pass around shit that gets copied in functions, but in C++ tutorials around that seems to be something punishable by death.

Sometimes that is a bit annoying, because it makes me doubt every single line I write, because I know for sure that there is probably another better way of doing that, which will minimise the number of allocations or some other optimisation trick.

C++ people hate std lib

I have seen loads of people writing their own standard lib over and over, just because of "performances", "don't reinvent the wheel" seems to be translated to "you surely can do better than who invented this language" for some developers.

Free tools are there just not easy to find docs about

CMake is an amazing tool to generate Makefile, that will build your project, weirdly though, the docs around are a bit not so easy to approach by newbies like me, and most people tell you off online if you use one way or another to specify stuff on your Cmake files.
VSCode is amazing with the C/C++ and CMake plugins installed, still there are loads of manual steps to manually add files to make them compile.
CLion is not worth it, the only thing that does for you is generating files and adding them to CMake automatically.

I looked around and could not find any simple to use code generation tool that would amend CMakeLists automatically, so I made my own using hygen.

You can see how it works in this quick video demo.
CPP-VSCodeSetup

Package managers are weird and not really there yet

If you worked with Rust, Go, Php, Javascript, you love package managers, and depends on what you need to do sometimes it is impossible to work effectively without one, especially if you want to share the code.

VCPKG is the package manager that Microsoft is working on, and they have some cool tools in the pipeline, like a manifest file, like what packages.json does for node/javascript.
At the moment though they suggest to use gitsubmodules like so.

Load of GameDev Tutorial are copy pasted stuff

I did say multiple times that one of the reason for me to pick back up C++ was to get something out of it with Game Development.
I have been loving the youtube tutorials of TheCherno, even thought they are a bit too much on the windows side of things, so I had to adapt many things to use with CMake on a linux machine.

Apart from that every other "game dev" tutorial seems to be involving SFML example page, hardcoding linker instructions, copy pasting libs into folders and a copy pasted code from this book.

Unit tests are weird

It seems also really weird that the unit test lib, how to add them, how to work with them is not too well documented for newbies.
I tried GTest and Catch2, but so far I have spent most of the time configuring the tools rather than actually writing tests, which is annoying.

What's next?

Now I am planning to do some small projects with SFML, then testing OpenGL and SDL.

I am definitely going to work a bit more on the unit tests, I want to see if there is an easier way to add them to your project, and definitely if there is, I am going to add the test code generation to that tool I am using at the moment.

Let me know if you think I got something wrong or if something completely went under my radar, happy to hear other suggestions.

See you.

Top comments (0)