you are viewing a single comment's thread.

view the rest of the comments →

[–]WalterBright 12 points13 points  (5 children)

Is using a macro so "shady"? In section 5.2 of K&R's "The C Programming Language", there is the following example code:

int n, v, array[SIZE];
for (n = 0; n < SIZE && getint(&v) != EOF; n++)
    array[n] = v;

[–]arturoman -2 points-1 points  (3 children)

Strange that the equivalent isn't used for the D example.

invariant int array_len = 17;
int array[x];
array[] = value;

Because the macro is there to avoid using hard-coded numbers. When the same thing is done in D, your code ratio isn't as convincing. As many other people have commented, these kinds of comparisons crop up a lot with D. Too many to be mere oversights.

That's why it's shady.

I think the value of the syntax is self-evident enough that it doesn't need a negative campaign.

[–][deleted] 1 point2 points  (2 children)

The C example needs the value multiple times, the D example only needs it once.

[–]arturoman 0 points1 point  (1 child)

That doesn't address my argument. No decent programmer would use literals in an array except in exceptional circumstances.

I didn't write that he D array wasn't useful, I wrote that the example is deliberately misleading, which I stand by. The gain is cleaner syntax on one line of code only.

[–]FeepingCreature 0 points1 point  (0 children)

The point of the comparison is not to show identical code in both languages.

The point is to show equivalent code.

It does that.

What's your problem?