Comparison of Imaginary types
Damian McGuckin
damianm at esi.com.au
Sun Jul 12 01:13:21 UTC 2026
On Saturday, 11 July 2026 at 11:04:34 UTC, Nick Treleaven wrote:
> I forgot to reply to that. Don actually said C and D are
> different:
>
>> D can avoid the need for a pure imaginary type, because *D
>> guarantees constant folding, whereas C does not*.
While it is only my opinion, ...
I would agree 100% s a computer scientist and 200% if I was a
maintainer of a compiler. But I would argue that this is
outweighed by the clarity that an imaginary type provides to an
end user (and people writing documentation). I would also
apologize for my opinion to the person writing the compiler
because it means more work. D certainly has lots of advantages
over C. That said, in one of Walter's recent presentations, he
notes that an attribute of Elegant Code is orthogonality. And
having real types, imaginary types and complex types is an
example of that. As an important aside, I will note that the line
containing the link to that presentation on Walter's home page,
the link to the Elegant D symposium has a typo, i.e. instead of
dlangsymposium.com, it says dlangsymposiumlcom. Oops. Someone's,
maybe Walter's, fat fingers typed the 'elle' key rather than the
'dot' key which is just below it on the keyboard. I regularly
type m instead of a comma for the same reason. Sorry, I digress.
I could not understand why Don thought the C99 imaginary type is
a hack. I know one of the authors of the document supporting its
inclusion very well and I have rarely had cause to question his
insight. And the other author is a legend and a winner of the
Turing award (not that such an award makes him infallible, just a
lot wiser than I).
That use of UFCS to allow one to write "4 + 2.i" highlights the
power of D. Nice one.
Thanks heaps for the feedback and spending time replying to my
questions. Coming back to D after 15+ years is a steep relearning
curve.
More information about the Digitalmars-d-learn
mailing list