Carmack about static analysis

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Dec 24 20:44:55 PST 2011


On 12/24/2011 07:20 PM, Adam D. Ruppe wrote:
> On Saturday, 24 December 2011 at 23:51:57 UTC, bearophile wrote:
>> Using certain abstractions sometimes helps to write one idea only once
>> in a program. Etc.
>
> This is the biggest one, and applies to all kinds of code.
> I like to write little functions with meaningful names.
>
> bool isOdd(int i) {
> if((i % 2) == 0)
> return false;
> else
> return true;
> }
>
> filter!isOdd(myCollection);
>
>
> I find that nicer than
>
> filter!"i % 2 != 0"(myCollection);
>
> despite it being longer.

Different strokes for different folks. IMHO it would be difficult to 
justify the verboseness and the unnecessary (twice) flow of control. I 
see every letter beyond this as a liability:

bool isOdd(int i)
{
     return (i & 1) != 0;
}

> With the former, it says very simply that it wants odd
> numbers at the usage location.

Giving an operation, however trivial, a symbol, is often a good thing. 
There are of course limits, and each engineer has their own ideas where 
to draw the line.


Andrei


More information about the Digitalmars-d mailing list