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

cym13 via Digitalmars-d digitalmars-d at puremagic.com
Wed Mar 18 17:34:28 PDT 2015

On Wednesday, 18 March 2015 at 23:41:41 UTC, Walter Bright wrote:
> On 3/18/2015 5:45 AM, CraigDillabaugh wrote:
>> You said that "Unfortunately" this thinking is going out of 
>> style "for good
>> reasons".   I am confused (sorry, I am at work, and didn't 
>> have time to watch
>> the 1+ hour video you linked to - maybe some clues were there)!
> Consider this C code:
> #include <stdbool.h>
> #include <stdio.h>
> typedef long T;
> bool find(T *array, size_t dim, T t) {
>  int i;
>  for (i = 0; i <= dim; i++);
>  {
>     int v = array[i];
>     if (v == t)
>         return true;
>  }
> }
> There are several bugs in it. I've showed this to probably over 
> 1000 programmers, and nobody found all the bugs in it (they are 
> obvious once pointed out). It is not easy to write bug free 
> loop code, and find() is a trivial function.

i is of type int and dim of type size_t which can grow bigger so 
the loop may overflow... I can't find more.

Either way, I think your point couldn't be clearer :)

Maybe there should be a "part 2" to the C-to-D little tutorial, 
one that shows how to code at a higher level introducing gently 
functional structures instead of just teaching how to write C in 
D. To stop thinking about steps to think about transformations 
isn't an easy thing.

More information about the Digitalmars-d mailing list