Course

D from the ground up

The speed of C with the comfort of a modern language

  • Beginner
  • 12 chapters
  • 198 min read

A hands-on introduction to D: one main function and writeln, values in int, double, string and bool, auto as the compiler naming the type, immutable and const and what each promise costs, text with std.string and to!string, decisions with if and switch, ranges with foreach, functions with defaults and ref, arrays and slices with std.algorithm, associative arrays with sorted keys, structs with methods and toString, classes and exceptions, a first template, and a capstone that sorts records into a formatted score report. Every idea runs on a real compiler.

What You'll Learn

  • Write and run a D program, and say what void main and import do
  • Name values with int, double, string, bool and char, and let auto infer a type
  • Use immutable, const and enum, and explain what each one promises
  • Measure, cut and rebuild text, and convert values with to!string
  • Choose a path with if and switch, and repeat work with foreach over a range
  • Write functions with default arguments, ref parameters and overloads
  • Grow an array, slice it with the dollar sign, and use std.algorithm on it
  • Count and look up values in an associative array, printed in key order
  • Model a record as a struct with methods, toString and an immutable form
  • Throw and catch an exception, with an error class of your own
  • Write a function template once and let the compiler instantiate it per type
  • Assemble a report from records, a sort rule and formatted numbers

Prerequisites

  • No D at all — the course starts at the first program
  • Skill with any other compiled language makes the early chapters quicker, but none is assumed

Course Content

  1. 01
    Your first D program

    What D is for, what the compiler needs before anything runs, and the smallest complete program: one main function, one import, and a few lines of output.

    Beginner · 12 min read

    Not started
  2. 02
    Types, values and auto

    The five types you will use every day, what auto really means, and the one place where whole numbers and fractions disagree.

    Beginner · 14 min read

    Not started
  3. 03
    immutable, const and enum

    Three ways to promise that a value will not change, what each promise costs, and why the compiler takes them more seriously than a comment.

    Beginner · 13 min read

    Not started
  4. 04
    Text: strings, slices and to!string

    Measuring and cutting text, the verbs std.string and std.array provide, and the conversion that turns any value into a string and a string back into a number.

    Intermediate · 17 min read

    Not started
  5. 05
    Decisions and loops

    Choosing a path with if and switch, walking a range with foreach, and the rule that makes a D condition different from the same condition in C.

    Intermediate · 17 min read

    Not started
  6. 06
    Functions, defaults and ref

    Naming a piece of work, letting a caller leave an argument out, changing a value through ref, and letting one name cover two kinds of argument.

    Intermediate · 16 min read

    Not started
  7. 07
    Arrays, slices and algorithms

    Growing a list, cutting a window out of it with the dollar sign, copying before sorting, and the three std.algorithm calls that replace most loops.

    Intermediate · 18 min read

    Not started
  8. 08
    Associative arrays

    Looking a value up by key, counting occurrences without writing a search, the difference between asking with in and reading a key directly, and why the keys need sorting before they are printed.

    Advanced · 16 min read

    Not started
  9. 09
    Structs with methods and toString

    Gathering related values into a type of your own, giving that type behaviour, teaching it to describe itself, and making a finished record immutable.

    Advanced · 18 min read

    Not started
  10. 10
    Classes and exceptions

    The one place this course uses a class, how throw moves control to a catch, and how to give a failure its own type and message.

    Advanced · 19 min read

    Not started
  11. 11
    Templates: one function, many types

    Writing a function once and letting the compiler make a version per type, reading the exclamation mark in code you have already used, and what an error inside a template looks like.

    Advanced · 16 min read

    Not started
  12. 12
    Capstone: a score report

    A program that uses the whole course: records in a struct, an array of them, a sort with your own rule, aligned columns, and a total with one decimal place.

    Pro · 22 min read

    Not started