Back into C++ in 2021: First Week
Tags: cpp, gamedev, cmake, sfml
Published: 2021-03-24 20:49:49

---
title: Back into C++ in 2021: First Week
published: true
description: 
tags: cpp,gamedev,cmake,sfml
//cover_image: https://direct_url_to_image.jpg
---
as I said in the previous [post](https://dev.to/vikkio88/what-do-i-need-to-go-back-to-c-in-2021-4ha8), 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](https://github.com/vikkio88/cppLearningExercises/blob/main/thrTest/src/main.cpp#L22):) god it feels good to do multithreading in C++, and it is as easy as any other modern language.

[Smart pointers](https://en.cppreference.com/book/intro/smart_pointers) are amazing, and it makes managing memory a breeze, and easy to read track down.

[Algorithm](http://www.cplusplus.com/reference/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](https://cmake.org/) 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](https://www.jetbrains.com/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](https://github.com/vikkio88/hygenTemplates) using [hygen](https://www.hygen.io/).

You can see how it works in this quick video demo.
[![CPP-VSCodeSetup](https://img.youtube.com/vi/MsJmAMvNYwI/0.jpg)](https://www.youtube.com/watch?v=MsJmAMvNYwI)

### 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](https://github.com/microsoft/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](https://spinicist.org.uk/posts/vcpkg-part1/).

### 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](https://www.youtube.com/playlist?list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb), 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](https://www.sfml-dev.org/) example page, hardcoding linker instructions, copy pasting libs into folders and a copy pasted code from [this book](https://www.packtpub.com/product/sfml-game-development/9781849696845).

## 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](https://github.com/google/googletest) and [Catch2](https://github.com/catchorg/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.