null references redux + Looney Tunes

bearophile bearophileHUGS at lycos.com
Mon Oct 5 03:34:33 PDT 2009


Nick Sabalausky:

> -- fig A -----------
> open(inFile ~ "out" ~ inFile.file ~ "log");
> // As many as 4 different errors that could be caught but currently aren't.
> // (But obviously all would be overridable, of course)
> // Without such checking, if inFile contained "/usr/home/joe/foo/bar.dat",
> // the result would be:
> //   "/usr/home/joe/foo/bar.datoutbar.datlog"
> 
> // Meant to do this:
> open(inFile.path ~ "out/" ~ inFile.name ~ ".log");
> // Result now: "/usr/home/joe/foo/out/bar.log"
> ---------------------
> 
> -- fig B -----------
> int add(int* a, int* b)
> {
>     return a + b; // Error currently caught
>     // Meant:
>     return *a + *b;
> }
> ---------------------
> 
> -- fig C -----------
> auto accel = velocity * time; // Error caught with that "dimensional 
> analysis"
> // Meant this:
> auto accel = velocity / time;
> ---------------------

Scala has a powerful type system that allows to implement such things in a good enough way:

http://www.michaelnygard.com/blog/2009/05/units_of_measure_in_scala.html

Bye,
bearophile



More information about the Digitalmars-d mailing list