When would one define a method/function with the private modifier in a class as opposed to nesting it within the principal calling method/function? Is there a performance hit when nesting functions?
Asked
Active
Viewed 1,294 times
1
-
Either the function is use as oneshop lambda, or it's used privately from many place. – cchantep Sep 15 '14 at 16:55
-
1Seems what you are looking for is answered pretty well here: http://stackoverflow.com/questions/2482326/the-cost-of-nested-methods – Shyamendra Solanki Sep 15 '14 at 17:13
1 Answers
1
I don't think that you're App is less performant when using nested functions since they are moved to class level during compilation (The cost of nested methods). But it helps you to have the smallest scope as possible, which is a good class design.
So if no other method is using your def, it is a good idea to define it as a nested function.

Community
- 1
- 1

cokeSchlumpf
- 163
- 1
- 9