Smart slicing

bearophile bearophileHUGS at lycos.com
Mon Mar 31 05:08:07 PDT 2008


Jesse Phillips:
> while(true) {
>     auto subStr = str[0..i++];
>     //Do stuff with subStr
> }
> I just wanted to point out that if a variable is used an the programmer 
> wishes to stop the said "loop" when you have reached the end but forgot 
> to check, you have a working program that false to work as expected.

In C/C++ you often put bugs like that in the code because:
- you are using too much low level abstractions: higher level functions (like map, filter, etc, and list comp/generators too) allow you to iterate and process collections avoiding to manage indexes by yourself.
- the syntax is so cluttered that it doesn't let you see the bugs well;
- You don't have an interactive shell to try every little snippet of code;
- (and there are other causes too).

Bye,
bearophile



More information about the Digitalmars-d mailing list