Previous Entry Share Next Entry
Explaining Language Design (Part 8: Essential Complexity)
Finally Scott finishes the talk about essential complexity. This is essentially a recap of Part 2 for D.

void main() {
    struct Point {
        int x, y;

    Point p;
    static assert(is(typeof(p.x) == int));

    const Point* cp = &p;
    static assert(is(typeof(cp.x) == const int));

Scott claims that 'cp.x' could lagitimately be consider of type 'int' or 'const int' and shows C++ which allows for obtaining either:

decltype(cp.x) // int
decltype((cp.x)) // const int&

As mentioned in Part 2, const is transitive in D. So there is only one right answer, cp.x is 'const int.' Again you can use std.traits.Unqual to get the unqualified type and cp.x can still be assign to a new variable of type int.


The choice for const to infest the entire type has removed some complexity of the language, but it has also made working with const more of a challenge (especially since it can't be used the same as it is in C++ or other languages).

  1. Part 1: Default Initialization
  2. Part 2: Const Inference
  3. Part 3: Lambdas in C++
  4. Part 4: Lambdas in D
  5. Part 5: Type Inference
  6. Part 6: Inheritance
  7. Part 7: Algorithm Complexity
  8. Part 8: Essential Complexity


Log in