#013 – Avoid default initialization for variables

Consider the following This is default-initialization. This defines the variable with a garbage value (not zero). If we print its contents, it will be whatever value is sitting at that memory address. Who knows! When you don’t initialize a variable,…

#012 – Prefer ‘\n’ over std::endl

When using std::cout we typically return a new line at the end of each statement for cleanliness. Despite std::endl being designed to serve this purpose, it is more efficient to use '\n'. This is because the later doesn’t flush the…

#010 – The modern way of variable initialization

Defining a variable is called definition. Giving a variable a value is called assignment. Initialization merges these two instructions into one statement. E.g. int x { 11 }; This is the modern way of variable initialization. The historical way is…

#009 – How to use comments

I’m a big advocate of comments. It conveys the programmer’s intent, which is very useful if you’re interpreting someone else’s code. How to use comments A comment should communicate what a function or library does. For example: A programmer should…

#008 – Choosing your language standard

As part of configuring our compiler, we can select the language standard or version. Recall that various versions exist including C++98, C++03, C++11, C++14, C++17, C++20, C++23. Which language standard should you choose? Whilst you might think to choose the…

#007 – Warnings and error levels

When the compiler encounters an issue it will emit a diagnostic message or diagnostic for short. The C++ standard does not define how diagnostic messages should be categorized, worded, or how those issues should affect the compilation of the program.…

#006 – Build configurations

A build configuration are the settings the IDE uses to build your project. The build configuration typically includes things like what the executable will be named, what directories the IDE will look in for other code and library files, whether…

#005 – How do we develop programs? Part 2

Here’s the flowchart from the previous nibble, we let off from Step 4. Step 4 – Compile the program The compiler performs two functions (get it functions): Step 5 – Link object files When we create C++ programs, we split…

#004 – How do we develop programs? Part 1

Now, I’m sure you’re itching to develop your first programs. However, it save us alot of headache, it’s wise to discuss the workflow of programming because ultimately, the program exists to solve a problem. Let’s make that step 1: Here…