In the past classes, we have used JavaScript and Lua to write code. For this class, we are going to be using the D Programming Language to build simple text-based and 2-d games. D is a compiled language, which is different from languages we have been using so far. A compiled language converts or "compiles" the source code into machine code, which is then run directly by the computer. No translation or interpretation is needed once it is in machine code, which means it can run faster (generally speaking) than interpreted languages.
D also can directly use C compiled code. The C Programming Language is a compiled programming language that has been around since 1972, and still remains the most popular programming language for compiled code in existance. We will use D because it is a much nicer language than C, but because we can call into C libraries with almost no effort, we get access to all the libraries that C developers have written, including some nice 2-d graphics libraries.
To use this, we need to install a compiler for D, and an editor/debugger that supports D. We will be using Visual Studio Code (not to be confused with Visual Studio), along with the code-d extension that adds D support. This document will get you through the process to install all the tools necessary, and to compile and run your very first D program.
Please follow these instructions EXACTLY, and if you need help with anything, let me know on discord.
NOTE: If you are using an operating system other than Microsoft Windows, DO NOT follow these instructions, please let me know, and I can help you install it.
Even though we will not be using Visual Studio, we still need to install the C/C++ compiler, and the tools associated with it. D needs a C library to use, and this is the main one on Windows. Luckily, we don't have to install the full version.
Go to the Download Page, and click on the correct item:
Select the C/C++ workload, and then click install:
When the installation is complete, you will see this page, you can just close it:
Download the D compiler from the D Download page. Click on the Windows installer and follow the instructions as identified in these images (leave everything as the default):
At this point, make sure you reboot your computer. This step is important, or the compiler will not be found by the editor.
If you are successful, you now have all the tools installed needed to build D programs. However, we also want a nice environment to edit and build our projects.
Visual studio code can be found here. Click on the download button as shown in this image:
As before, click on the "Run" button, and accept all defaults. At the end, it asks you to run vscode, you should do this now.
You will see a welcome page that looks like this:
Click on the "Extensions" button as indicated. This will show extensions you can install to edit different types of files. Type in the term dlang as shown here:
The extension we are going to install is called code-d by "WebFreak". There are two options, select the one that says "utility extension package". That actually includes the other one, as well as debugging support.
Now we need to install a debugger. Because D is so closely related to C, we can install the C/C++ extension, which includes Microsoft's excellent debugger software. Do this by searching for C++ in the extension window, and installing the one that just says C/C++ by Microsoft:
To test that everything is working (we won't be using the debugger yet, but this will at least test your D compiler), let's create a new project and build and run it!
Congratulations! you just built your first executable program. You can run it directly from a command line if you want to see it work without Visual Studio Code. Click on the start button and type 'cmd'. Then, run the Command Prompt app. Inside the app, you will be in your home directory. type cd Desktop\testing, and press enter. You are now in the directory of your program. Type dir, to see your program named testing.exe. type testing to see your program run!
©2020 Steven Schveighoffer