Remove complex and imaginary types?

Bill Baxter dnewsgroup at billbaxter.com
Mon Jan 7 01:17:52 PST 2008


Walter Bright wrote:
> The issue comes up now and then about why have complex and imaginary 
> types, rather than using structs? All but one of the advantages of 
> having them be core types can be addressed with advancing compiler 
> technology. Getting rid of them will release 6 keywords, and make the 
> core language simpler. Given the increasing complexity of D, this will 
> help.
> 
> The remaining advantage is that of imaginary literals, i.e. the i postfix:
> 
>     3 + 5i
> 
> Assuming we solve the literal problem, existing code would only need to 
> add:
> 
>     import std.complex;
> 
> to acquire complex and imaginary types.

While some way to write complex literals would be neat (because 
presumably it would open the door to being able to make literal syntaxes 
for all user types) I don't think it's really a killer.

It's not very common to use lots of literals.  For a command-line tool 
not having a literal syntax can be a bummer, but for a programming 
language it's bad practice to have a lot of magic literals in your code 
anyway.  I.e.

    creal rot45 = creal(.707, 707);
    creal xr = rot45 * x;

is better than
    creal xr = (.707 + 0.707i) * x;

in my opinion.  As long as complex constants can still be put in static 
arrays, it should be ok.

--bb



More information about the Digitalmars-d mailing list