Unknown W. Brackets wrote:
>> http://www.bitwisemag.com/copy/programming/d/opinion/d_programming_language.html> Pardon me, but why is there a screenshot of a C program and compiling it
> with DMC on the D page?
It's been changed into "hello.d" now.
However, it's still using some questionable practices, that is:
int main(char[][] args)
{
printf("hello world\n");
printf("args.length = %d\n", args.length);
for (int i = 0; i < args.length; i++)
printf("args[%d] = '%s'\n", i, cast(char *)args[i]);
return 0;
}
Both printf and that cast are just "crashes waiting to happen",
and we also have our friend "the missing: import std.c.stdio;"...
However, if you convert it over to something more in D - like:
import std.stdio;
void main(char[][] args)
{
writefln("hello world");
writef("args.length = ", args.length, "\n");
foreach (int i, char[] arg; args)
writefln("args[%d] = '%s'", i ,arg);
}
Then you must also make sure to include instructions to set the
console/terminal over to UTF-8, or run into the famous i18n "bug":
# ./hello abc åäö
hello world
args.length = 3
args[0] = './hello'
args[1] = 'abc'
args[2] = 'Error: 4invalid UTF-8 sequence
But I don't think that is "reason enough" to stick with old printf,
just because that it works with the legacy encodings out of the box.
Still, it would be nice if we could get all these "introductory" items
addressed - before there are any newcomers to D that are scared off ?
Hope the new sites will help with this.
--anders