Setup And Configuration - itzjac/cpplearning GitHub Wiki

Development Tools

The Holy Trinity of Programming Tools

The three fundamental tools to software development, what I define as The Holy Trinity of Programming Tools: text editor, compiler and debugger.

That's no exception to C/C++ programming, extend it to almost any other language you can imagine.

Up until this day, there is a never ending discussion on which is the best one. When you are just starting, making your mind up and picking the right one, is darn hard. You wouldn't even know what it means a good text editor for starters. It is a very opinionated topic, and you know what's the popular consensus about opinions.

The important aspect is to understand the three fundamental tools, the holy trinity of programming tools. As you grow in experience, you can pick whichever you think fits the better to your mental model.

Personally, I think having the power to do everything on your own and understanding it as deeper as possible, will always bring you the best results. Not the easiest way, not for everybody, but in the end it pays off.

Though I joined late to the programming scene, I did start with the most common ones back in 1999, the list is extensive and probably not a complete one. vi, vim, nano, gedit, notepad(oh, really?), TurboC, Turbo Pascal, BorlandC, Visual Studio 6, Netbeans, Eclipse.

As my professional and personal projects evolved, the problems started to emerge. Call it pure text editors or IDEs, freezing machine, freezing app, BSOD, slow and long loading process, backward compatibility, corrupted files, known bugs. With every new generation of editors/IDEs, that translated into work to port to the latest. Specially with IDEs, if you have several old projects to port, would have been a significant amount of work, not to forget that you also had to swallow the bug pill (entire batch of bugs coming with the latest releases).

I always tried finding for alternatives that minimized dependencies from the IDEs and the OS. And it was the time that other build and scripting tools like make, NMake, CMake started to take relevancy on my portfolio. They are good, they do the job, is just not as nice as you would expect and it does end adding third party dependencies.

So, my conclusion landed here: try as much as possible to stay away from third party tools, IDEs and non-native script languages for automation. Engines like UE4/UE5 with a massive amount of money and team size at their disposal, have also created their particular framework to keep automated the port pipelines and up to date. It definitely works, but believe me is not even perfect.

Software development quality, their process, pipelines must continue to improve, and so for the programming tools. There is no reason to prevail with old bad practices, if you are reinventing the wheel, let it be a better wheel!

Having spent a considerable amount of time doing scripting automation, build systems for C/C++ programs, trying as many text editors. Those experiences are the backbone for this material: save your time and the pain, the best to do is all on your own. By doing it yourself you will learn more, it will be portable, it will be customizable and it won't contain the myriad of unknown bugs and dependencies, it will help you to be a better programmer.

If the "do it yourself" philosophy is not your cup of tea, there are plenty of decent free options out there, save your time and let me try pulling you back from the most annoying ones, the rest is up to your preferences. Sticking to one tool that will do the job is also an option, some jobs and companies do embrace that fact.

Never forget and be aware of the bigger picture, the holy trinity of programming tools is all what have at your disposal in reality.

Text Editors

Some of the most popular text editors to create C/C++ source files are:

  • emacs (author's favorite)
  • Sublime
  • vim the most popular on Unix-like systems
  • notepad
  • notepad++
  • gedit
  • ConText
  • nano
  • pico

C++ Compilers

Every operating system implements its own version of a C++ compiler.

Compilers can be:

  • Distributed as a StandAlone tools or along with an IDE(Integrated Development Environment).

  • Open source or proprietary.

Some of the most common C++ compilers:

  • gcc Unix-Like systems, the GNU Compiler Collection
  • mingw the gcc version for Windows/MacOS, https://www.mingw-w64.org/. For a more precise and direct download here
  • Cygwin
  • cl VC Windows only

A more extensive list of C++ compilers.

Every compiler provides a command line functionality, despite their distribution.

It is crucial to a serious C/C++ programmer to understand how a compiler works from the command line, rather than being limited to memorizing an specific IDE or UI layout. Moreover, by using the command line is possible to build from the ground up a development framework that can be improved and reused on several systems, perhaps even between different OS's.

This is why we will start working from command line when jumping in to our C/C++ programming chapters.

HANDS-ON: Locate the tools in your OS

Unix-like systems are usually distributed with programming tools like the gcc compiler, is usually enough to open a command line terminal to get access to the compiler. If those tools were omitted during the installation process, apt install facilities will get you ready. Windows tools have to be installed independently, manually being Visual Studio Community 2019 or 2022 the most common and used

It is important to always verify its version, the OS might contain a 5 or 6 years old compiler that surely needs to be updated.

Command line terminal prompt in this course will be presented as:


LINUX
dagon@linux-desktop:/home/dagonmeister$
WINDOWS
C:\cpplearning>

It is recommended to keep short paths, no spaces for your working environment as shown.

For brevity and clarity, we omit any of the local paths references and we will only use the dollar and angle bracket to differentiate between the different OS command line prompt types.


LINUX
$
WINDOWS
>

It is always recommended to verify the availability, status and version of your compiler using the command prompt.


LINUX
$g++ --version
++ (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
WINDOWS
>cl /help
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30136 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

We will be using from listed versions or above.

Now, knowing the C++ compiler is ready to be used, create a special dev directory in your home which I will call 'dev'.


LINUX
$mkdir dev
$cd dev
WINDOWS
>mkdir dev
>cd dev

Now you are located in the dev folder/directory from where we will begin to add our code.

Debuggers

Microsoft Debugger suites

  • VC Debugger, this is what comes in the behemoth bundle within the guts of VC, never had the need or the idea to try to isolate it, is what you will usually use by just pressing F5 in you VC solutions or projects

  • WinDBG an amazing standalone tool, often forgotten and ignored. It is used regularly on kernel driver/internal graphics driver debugging environments. Having a machine to develop and play your games in steam, is not a good idea. Thanks to WinDBG I managed to locate the source of a crash when launching one of the steam games. The reason was, by installing the DirectX SDK I turned Debug mode ON (was it really me or it was during installation, can't recall). Some games just crashed on startup and weren't capable of execution. Lesson learned!

The alternatives

  • gdb, the facto standard cross platform option, almost exclusive to a the command line environment, used extensively for Linux OSs. Apendix C contains a detailed tutorial how to configure and use gdb, targeted to learn more about assembly code and how to use it for disassembly

  • Remedy BG, developed from ground up. With the goal of replacing the behemoth VC debugger and realizing that debuggers have largely been stagnant in their progress over the last couple of decades

  • Look into the force, the cloud has it all nowadays.

IDE's

All in one place, Integrated Development Enviroments(IDEs) are software suites that are created on top of the Holy Trinity of Programming Tools, is a another software layer hiding you details. They will provide beyond the basics and have: special syntax highlight, specific language features, performance profiling, refactor, code snippets, markers, UX. You will have to struggle ignoring all the clutter, and unnecessary tools to actually get them to work exactly as your project needs. The one that's a mandatory requirement to learn is the Microsoft one.

Microsoft Visual Studio, being at the top of the list for game development with C/C++ will be mentioned several times through the material. Microsoft Visual Studio has support for .NET, C/C++, Python, Java, JavaScrip, TypeScript, Web and much more. .NET itself is a category of Microsoft developed languages that include C#, F# or Visual Basic. From now on, as we strongly focus on C/C++ we mostly refer to VisualC (VC) in the text, for the subset of tools and features related to that language in Visual Studio.

Text files format, source code and cross platform

A notable characteristic of the editors between OS when writing C++ code, are the file’s Line Ending which come in the Unix/Linux, Windows and Mac OS type.

In Unix/Linux it means that the editor (i.e. gedit) will insert (invisibly) \n at the end of any line of text that you type.

In Windows, by contrast, uses \r\n, and Mac OS uses \r.

On your own

4coder

Guaranteed, any of your popular text editors or IDEs, will lack and have problems in some areas, shine in others. Personally, I have followed a handmade/from ground up/super efficient and fast editor that supports cpp, c along with JAI and native scripted files for WinOS or Linux. The source code is available in github, the editor is a fully customizable gamedev env 4coder. Projects like this really open the possibilities, admirable effort to offer an optimized and customizable editor that can become an full IDE. If you want to go on your own, willing to get your hands dirty, 4coder is a great win!

Few hints.

  • Coming from Emacs and directly downloading the distributable binaries, took me 2mins to reconfigure my dev environment to 4coder.

  • I did also try 4coder compiling it from source code and even using customized extension, my advice is that was way more work than expected.

  • If you are planning on collaborating on a cool project, this might be a great starting point.

  • Already used 4coder to code with assembly, no need to download SDK like masm32 or similar. Pick an assembler, likely a compiler with the assembly and linking tools (mingw, VC have those tools included) and you take it from there

Having said that, 4coder is an awesome editor. Choose your favorite installation flavor

A very basic list of commands to warm you up ---> here.

Emacs

Emacs can be thought as an entire OS. You can even run some classic video games inside it. The most annoying part in Emacs is not about memorizing the commands and keyboard shortcuts, but learning its own Lisp language version. You will spend a lot of time revolving your head around this language.

Without a question, guarantee there is support for almost anything you can imagine for an editor in the Emacs extensions. MELPA is one of the biggest package repository for Emacs extensions. Check out this extension to detect assembly language (masm flavor).

ASM language support masm-mode, masm-mode will clobber Emacs’s basic and almost useless built-in asm-mode. Download the .el file from MELPA.

Copy the .el file, to the ~/.emacs.d/ directory (usually something like C:\Users\myser\AppData\Roaming.emacs.d in Win OS), and add the following in your .emacs file:

(add-to-list 'load-path "~/.emacs.d/")
(load "masm-mode")
⚠️ **GitHub.com Fallback** ⚠️