This course shows off D, a systems programming language designed to replace C++ with a simpler syntax yet the same amount of power. D is a modern, multi-paradigm language that compiles into native code. It is famous for its speed and elegance, and is getting more and more traction with developer audiences.
This course introduces D, a systems programming language designed to offer the same power and flexibility as C++ coupled with the convenience of features found in modern programming languages such as C# or Java. D is a native, compiled object-oriented programming language that manages to avoid some of C/C++ shortcomings such as imprecise data types or the need for manual memory management. On the other hand, D lends itself to performance-critical tasks: if needed, it supports various performance-improving approaches such as an ability to disable array bound checks. This course covers the basic features of D, such as its type system, support for error handling, the way it handles OOP as well as D's approach to concurrency.
Types and Operators In this module we're going to look at the most fundamental building blocks of all software, the core data types that I use to store numbers and characters, as well as operators that allow you to assign and modify them. So, we'll take a look at first of all the integral types, the data types that store whole numbers, and then we'll take a look at floating point types. These are the data types that store numbers that have a fractional component. We'll then take a look at complex numbers, which is something that's unique to D and something you'd expect from computer algebra systems such as MATLAB for example. D happens to support those as well. And then we'll take a look at character types, and we'll also mention strings, although those get a separate module of their own,. And finally we'll look at the operators that allow you to actually manipulate the data that's stored in these data types.
Control Flow In this module we're going to talk about control flow statements. These basically control which parts of the program execute and which do not. So, we'll talk about some fairly basic constructs in this module. We'll start with the if statement or the if-then-else statement, and I'll also remind you once again about the ternary operator that you can use instead of the if keyword. Then we'll look at something that's very much unique to D, the static if statement. Then we'll look at the for loop, the switch statement, and the while loop. If you're an experienced developer, you'll most likely be interested in the sections that I've marked with a red asterisk. Static if is something that's unique to D whereas the switch statement has a peculiarity that's absent in modern programming languages, so you might want to check out that section too.
Arrays and Strings Welcome to another module in the D course. This module is about arrays and strings, and these are useful when you have a situation where you have some homogeneous data that you need to store somewhere. And you typically use arrays for this. You use array as a kind of grouping mechanism to put several items which are similar in terms of type together into one construct. So, in this module we'll take a look at how to work with arrays, and we'll also look at strings, which are just arrays of characters. We're going to talk about fairly basic constructs, but keep in mind that some of those constructs are related to D specifically, so users of C++ and other languages might be interested in how those work. We're going to begin with dynamic arrays, and we'll continue by talking about fixed arrays. Those are arrays whose size is predefined. Then we're going to talk about multidimensional arrays, how you work with arrays of more than one dimension. Then we're going to talk about associative arrays, which indeed are actually built into the language as opposed to being provided as part of a library. And then we'll talk about strings.
Functions When you've got many statements that all relate to each other in some way and form a part of a task together, chances are you want to group those statements together, and functions, which are also known as methods in some programming languages, let you do precisely this, so this module is all about functions, how to create them, and how to use them, and it also happens to be the first module where we dive into some fairly complicated features supported in D. We've actually built all of the examples in the previous modules out of very simple functions, but we're going to begin this module with a look at what the functions actually are and how they are invoked. We'll then discuss in quite some detail the ways in which parameters can be passed to functions. Now, usually the number of parameters is known in advance, but if it's not you can write a so-called variadic function that takes any number of parameters. We'll also look at the tuple data type as an illustration of the power of variadic functions. We'll also discuss type parameters, which define the types of the parameters that are being passed into the function, and this is a slightly more complicated concept, but it's crucial for what comes next. So, next up we'll talk about overloading, the way that you can have several functions with the same name, but taking different parameters. Then we'll talk about nested functions, those are basically functions inside other functions, and we'll also talk about function literals. And after that we'll discuss a particular feature of D that lets you interchangeably call a function with a parameter. I'll call a function on that parameter as if it were a member function instead.
Object Orientation Unlike all those exotic multi-paradigm languages that seem to have come on the market recently, D supports the good old-fashioned paradigm of object-oriented programming, so in this module we're going to take a look at the way that D supports OOP. We're going to begin by discussing what exactly OOP is and why you should care. Please note that since this module is effectively an introduction to object-oriented programming it might be of less interest to experienced developers who are coming to D from other languages. So, after an exposition of OOP we're going to take a look at key language features that make it possible, classes and the fields and functions which those classes contain. We'll then need to talk about nested classes, which is the idea of having classes inside other constructs, not just classes mind you. The visibility and availability of class members is what allows one to have the three pillars of OOP, namely encapsulation, so we'll take a look at what aspects of the language support this paradigm. We'll then talk about static members. Those are members which belong to the class as a whole rather than any individual instance of it. Then we'll talk about inheritance, which is all about inheriting certain traits or members from other types in the hierarchy. Then we'll talk about abstract classes, which are classes without an implementation that serve only as base classes, as well as interfaces. We'll then talk about polymorphism, which is another key idea of object-oriented programming. We'll then talk about the object type, which is the root type in the D language, and we'll talk about the methods that you can redefine to make your type play well with other parts of the D infrastructure. And we'll finish off this module with a discussion of type parameters.
Error Handling One of the key aspects of programming languages is what facilities exist to help developers deal with the errors that may occur during the execution of the program, so this is what this module is about. We're going to begin by discussing the idea of exceptions as an error handling mechanism, and we'll take a look at how you throw exceptions, how you catch them, and what happens if you fail to catch one. Then we're going to delve into the rather simple exception hierarchy that D supports, and we'll also discuss how to handle different exception types within a single try/catch block. Then we're going to talk about the finally clause that lets us execute some code regardless of whether we caught an exception or not. Then we'll talk about a more curious case of what happens when a finally clause also throws an exception because D has a solution for this too. And we'll finish off the module with a discussion of D's approach to checking array bounds because D has some special options in this regard.
Contract Programming Now, let's talk about contract programming. The idea of contract programming, it basically implies that there is a sort of a contract between somebody who creates an API and other people who consume that API. So, essentially it's kind of like a statement of what a particular function or a particular framework actually promises to provide and how it enforces certain conditions, and in this module we'll take a look at using contracts to check program correctness. So, in this module we're basically going to look at the four constituent parts of contract programming support in D. And they are first of all assertions, then we're going to look at preconditions and postconditions, and then we'll look at invariants, and we'll also discuss the execution order of all of these parts when it comes to actually checking the conditions.
Concurrency Concurrency is a pain point in modern programming. It's painful because programming concurrent systems is generally difficult and error prone, and much of the task of concurrent programming concerns this idea of protecting oneself from the various concurrency-related mishaps rather than leveraging particular architectures in the most efficient manner. So, in this module we're going to take a look at D's approach to the subject of concurrency. We're going to begin this module at a somewhat obvious demonstration of how to create different threads of execution, and we're going to see D actively resisting the very concept of sharing data. So, given that shared data is not desirable at least from D's perspective, how would threads communicate with one another? Well, there is a mechanism for that too. And then we'll talk about the ways of synchronizing access to functions meaning we will discuss how to control the issue of several threads accessing a single function without interfering with one another. And then finally, since this is the last module, I will say a few words about what we've learned in this course and where to find additional information on D.