Carmack about static analysis

Jacob Carlborg doob at me.com
Sun Dec 25 05:59:17 PST 2011


On 2011-12-25 02:20, 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.
>
> With the former, it says very simply that it wants odd
> numbers at the usage location.
>
>
> With the latter, you have to think for a second about
> what the modulus operator actually does and what the
> definition of an odd number is before you can get to
> why the filter is there at all.
>
>
> It gets even worse if the other function has non-trivial
> code. Best to just give it a name so you don't have to think
> about the implementation at all at the usage site.

I completely agree with this. It can be used in if-statements and 
similar as well.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list