-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
I often have the situation of functions taking a lambda-expression as a parameter which take a handful of parameters themselves. Something like this:
someFunction((foo, bar, thing, another) => ..);Of course, delegates with many parameters are often an indicator of bad design, and should be avoided. But it's the same with fewer arguments.
A situation like the above get's quite painful if the lambda-body does not even need all those parameters (or is in extreme always returning the same, constant value). But still, the compiler requests me to find unique names for each of the parameters. This is a problem especially when renaming / adding variables "above" the anonymous function which do then interfere with the unused variables there.
Most of the time what I do today is something like this:
someFunction((_, foobar) => ..); //Using '_' as a variable name somewhere around is highly unlikelysomeFunction((a, foobar) => ..); //Using short variable names elsewhere is highly unlikelyIt also helps reading the code, because I can save a few characters (getting more 'good' code into a line) and make it obvious for readers which variables are important to me, making the code more understandable.
Of course this is somewhat limited, because my "placeholders" are really just ordinary names which must not reoccur. This might lead to something like (_, __, foobar, ___) => .. which starts to look ugly again.
I would like it to have _ (or just another special character, for backwards-compatibility) not usable for ordinary variable names and forbid it's actual usage inside the lambda-body. Therefore it could be used as a real placeholder, enabling something like this:
someFunction((_, _, foobar) => ..);or even this:
someFunction((foo, _, bar) => bar.otherFunction((_) => foo));Does this sound like a useful thing to you?