0

isn't use of lambda function is against the rules.

Functions are to be created with the piece of code that is to be used multiple time. however lambda functions are to be used at once, so logically they don't even qualify to be function. Do you have any strong reason why to use lambda functions?

13th Mar 2017, 8:44 AM
Lutif Ali Mandhro
Lutif Ali Mandhro - avatar
4 odpowiedzi
+ 2
Lambdas don't have to be used only once. The only difference between a lambda and a named function is the lack of a name. Both can be passed around as objects and executed when needed. Example of lambda executed twice: f = lambda x: x * x one = f(3) two = f(4)
13th Mar 2017, 4:30 PM
Igor B
Igor B - avatar
+ 2
@Ali: I'm contrasting: f = lambda x: x * x with: def named_function(): return x * x f = named_function
13th Mar 2017, 8:08 PM
Igor B
Igor B - avatar
+ 1
@Igor isn't f = lambda x: x * x name the lambda as f() so it is no more anonymous.
13th Mar 2017, 7:50 PM
Lutif Ali Mandhro
Lutif Ali Mandhro - avatar
+ 1
Moreover, there is no rule that named functions must be used more than once. If you have distinct piece of functionality implementing a requirement, putting it into a separate function makes the code more readable, function name makes the code more self-documenting, and the implementation becomes more testable. All these benefits apply even if the function is called only once.
13th Mar 2017, 8:12 PM
Igor B
Igor B - avatar