Carmack about static analysis

bearophile bearophileHUGS at
Fri Feb 10 16:59:55 PST 2012

Jonathan M Davis:

> I just can't stand the idea that whether an if statement is true or not could 
> change the type of a variable (e.g. it's set to a string in one branch and an 
> int in the other).

You have found something that sometimes I like to do in Python, that I can't do in D, a reduced example:

import std.stdio;

int findSolution() {
    return -2;

void main() {
    int x = findSolution();
    writeln(x >= 0 ? x : "Solution not found.");

There are of course ways to perform to do the same in D too, but for me this is the most natural way to express that intent.

> I consider dynamic typing to be a _huge_ negative. It may 
> be fine for short scripts and the like, but I'll never write anything serious 
> using a dynamically typed language if I can avoid it.

If you try to add static typing to something like the Mathematica Language (that is a Lisp variant) you produce something that's probably unusable for those exploratory programming / mathematical purposes.

Racket has recently added a Typed Scheme, it uses gradual typing. You are able to add types to some functions of your program, and to use very specific types or more general ones as type constraints. They have even added a way to perform dynamic typing in C# (and it's way more than just having a variant type, they have had to change many things to implement it). I think the programming world is moving a bit toward a mix of static and dynamic typing (and a mix of functional and imperative/OOP programming).


More information about the Digitalmars-d mailing list