1

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?

RAbraham
  • 5,956
  • 8
  • 45
  • 80

1 Answers1

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