Using lambda expressions is not really a bad thing, e.g. in some LINQ statements. Along with the var, the lambda expression might be mostly for using with LINQ when it was born. And that might be also the initial idea why it came out.
It does help make LINK statements easier to write, read, maintain, and expand if lambda expression being properly used there than not possible before. However, if the lambda expression is abused, it would bring serious problems too. Using it in event callback functions might be a bad practice among all those.
Firstly, there is no a clear way (or even not at all) to remove the exact event handlers represented by those lambada expressions.
Secondly, its performance may be also an issue. Many times, we declare a static callback handler and assign it to an event at different times and in many different places and remove it when necessary. The lambda expression callback is always local, isn't it? Calling the event registration method containing the lambda expressions again and again or in different places will make the performance poor, won't it?
Thirdly, it is not readable or maintainable. If the event callback is separated out from the registration code and other logic, when something wrong with the event handler we can just look at the code and trouble shoot inside there; if event registration code is wrong we just look at the registration relevant part; if logic is wrong we just correct it. That is what methods/functions are for, right?
Fourthly, it makes some methods unnecessarily too long but some very necessary methods gone. In general, a method/function should be at most around dozens lines of code, but if all event callbacks are written with lambda expressions, the event registration method will be obviously too long, and no good event callback functions anymore. Good???
There are some other reasons. Googling it before doing so might have gotten better ideas.
That explains why our software such as AutoCAD .NET Addin Wizard does not use the lambda expressions in any event handlers. It is not we don't know or like lambda expressions. It's simple like that not proper in the circumstance. As demonstrated previously, all the event callbacks, the event registration and unregistration, and the hookup into the Extension Application are all structured and handled well there.
The latest build of AutoCAD .NET Addin Wizard 2015 can be downloaded and purchased from the following page:
Recent Comments