A few notes on choosing between Go and D for a quick project

krzaq via Digitalmars-d digitalmars-d at puremagic.com
Sun Mar 22 16:15:50 PDT 2015

> Something like
>     while (n != EOF) {
>         n = read(fd, buf, sizeof(buf));
>         if (n==-1) throw(...);
>         if (strcmp(buf, PREFIX) == 0) {
>              return buf;
>         }
>     }
>     return NULL;
> Requires no prior knowledge, and have similar effect.

I'm surprised nobody commented on "no prior knowledge". How are 
you supposed to guess what strcmp(buf, PREFIX) does if you don't 
know the function? Why is it being compared to 0? What's this -1 
magic number? What does read do? What is EOF? Unless you're born 
with C/POSIX programming knowledge, this is prior knowledge. I 
know C well enough, but it took me some time to understand what 
it does.

And honestly, compared to
>   File("/tmp/a").byChunk(4096).joiner.startsWith(s)
you can easily guess that you have a file - do some nonobvious 
magic on it - and check if it starts with `s` just by reading it 
as plain English.

More information about the Digitalmars-d mailing list