Unused variables and bugs

Idan Arye via Digitalmars-d digitalmars-d at puremagic.com
Sat Aug 23 08:48:03 PDT 2014


On Saturday, 23 August 2014 at 04:07:58 UTC, ketmar via 
Digitalmars-d wrote:
> On Sat, 23 Aug 2014 03:50:13 +0000
> via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
>
>> - versioning
> refactor it, so that shared code goes to separate functions. 
> nested
> functions especially helpful here. i'm used to this GCC 
> extension.
>
>> - debugging (commenting out debugging code)
> why comment it out? if (debug_enabled) is fine and can help when
> software fails.
>
>> - virtual functions
> they are either abstract or just comment out unused argument 
> names.
>
>> - future-proof function signatures
> but why? plan your API. if you need to extend it -- add new API 
> calls.

How about unused arguments in lambda expressions?

     import std.stdio;

     void foo(int delegate(int) dlg){
         writeln(dlg(12));
     }

     void main(){
         foo((x) => x+1); // No problem here

         foo((x) => 42); // Unused argument
         //foo(() => 42); // Error
         //foo(auto) => 42); // Error

         //We have to use:
         foo((int) => 42);
     }

Since `auto` doesn't work in lambda expressions, we have to give 
up on type inference for arguments we are not even using!


More information about the Digitalmars-d mailing list