On Thu, 29 Oct 2009 15:32:51 +0300, Jason House
<jason.james.ho...@gmail.com> wrote:
Denis Koroskin Wrote:
On Thu, 29 Oct 2009 15:12:51 +0300, Lars T. Kyllingstad
<pub...@kyllingen.nospamnet> wrote:
> I don't think he uses is(typeof(...)) in the text. The code snippets
in
> question are marked "Note: normally the code below would not be
> included...", and I suppose he's put them there as a reminder for
> himself and Walter on what needs to be fixed before the book comes
out.
>
> I agree with you, though, is(typeof(...)) is quite often misused, or
at
> least used in an ugly way. Why not use __traits(compiles, ...)
instead?
>
> -Lars
... which is at least as ugly.
I disagree. Code that isn't readily understandable is uglier than
readable code. Certainly, __traits is ugly, but it is easier to
understand when readig code and easier to write.
I was talking about ugliness, not readability.
There are only 2 places where is(typeof(...)) feature is used:
assert(is(typeof(somePrimes) == int[])); // perfectly fine IMO
static assert(!is(typeof(a[length - 1]))); // misused, yes
BTW, typeof is a bit inconsistent with .stringof, .alignof, .sizeof etc
(typeof(foo) but foo.sizeof).
Any chance this inconsistency is going to be fixed?
Either
assert(typeof(x + y) == int); -> assert(is((x + y).typeof == int));
Or
assert((x + y).sizeof == 4); -> assert(is(sizeof(x + y) == 4);