I also use _ => _.method() for a single-line, lambdas invocation method, as it reduces the cognitive weight of the command. Especially when using generics, writing x => x.method() simply adds that the split second consideration is "What is this" x "? Is it a coordinate in space?"
Consider the following case:
Initialize<Client> ( _=>_.Init() );
Used with a Generics call, the underscore in this case works as a bypass character. This avoids redundancy by determining that the type of the argument is obvious and can be taken out of use - just like using "var" to prevent the type declaration from repeating. Writing client=>client.Init() here will simply make the instruction longer without adding any meaning to it.
Obviously, this does not apply to parameters that must be passed to a method, which should be called descriptively. For example: Do( id=>Log(id) );
Using a unidirectional parameter for method calls is hardly justified when using a block of code instead of a single-line one, since the lambda identifier is disconnected from the definition of its generics. In general, when the same identifier is to be reused, give it a descriptive name.
The bottom line is that verbosity is justified only for values, especially for lambda, which were created to simplify the creation of anonymous delegates. In any case, common sense should be used, balancing clarity and brevity. If a character is just a “hook” for real functionality, then a single character identifier works fine. This is the case with For-loops and the letters "i" and "j" as indexers.
MaDDoX Jan 23 '17 at 13:19 2017-01-23 13:19
source share