The implementation of anonymous methods in C# and its consequences

When we use anomymous lambda in C#, we can have to choose between passing values as parameter or using lambda capture. Second one is elegant and easy: we “just” us enclosing variables.

It is good to remember that capturing has a cost which should be understood and taken into account. For this, we can refer to : The implementation of anonymous methods in C# and its consequences – The Old New Thing.

Knowing this, we can think that C++ 11 solution is better. We have to choose wich variables are captured and if capture is a copy or a modifiable reference in capture specification block ([]).  And, by default, there is no capture. That way, overhead it is not a hazard but a deliberate choice. Perhaps for C# 7 but with breaking changes.

Framework Design Guidelines Digest from dotnet/corefx Wiki

A qote from Framework Design Guidelines Digest · dotnet/corefx Wiki with which I completely agree:

Understand Your Customer

Realize that the majority of your customers are not like you. You should design the API for your customer, not for developers working in your close working group, who unlike majority of your customers are experts in the technology you are trying to expose.

Command line parsing in .Net

In my search for a simple and elegant library for parsing command line in .Net, I found two new candidates:

First one provides a fluent API really simple to use (only one gotcha: there is two github repo owned by same person and only old one details how usage can be printed on console with the elegant SetupHelp). Already used in a production code.

Second one seems to cover more powerfull options. This library is a minimal application framework centerer around verb notion (even if a default verb can be defined). The parser is in charge of running your application through a:
Parser.Run<TheApp>(args);
where your class TheApp declare methods corresponding to each verb. Each method parameters are gathers from command line according to attributes.

You have, among other things, validation (predifined with attributes and custom with code), pre/post condition for verbs, key shortening for verb and parameters and custom types in external file using either json or xml format.

Looking at CLAP’s code, I have found an ingenious way to validate key/value parameters using SQL Expressions builtin .Net  DataColumn.Expression (code is here). A DataTable is construct, a column is added for each parameter using its name and type and a single row is added to contain each value. In a small amount of line, you have expressions like “index1 > index2 AND index2 > 28”, “Name NOT LIKE ‘Test*'” or “Name NOT IN ‘Test1’,’Test2′” (parent-child relation referencing and aggregate functions are not usable but complete syntax is here).