Re:Code blocks in Python
by d4nt on Friday April 20, 2012 @09:37AM
(#3867799)
I'm not sure there is one. They're useful in C# as a way of defining a function within another function (which sometimes makes for more readable code). For example:
But in Python you can already define functions inside of functions so you have a better solution:
[ Parent
| on HN ]
> They're useful in C# as a way of defining a function within another function (which sometimes makes for more readable code)
Why wouldn't you just create another function in the same class?
Just personal preference really, if your "isRelevant" filter was only ever going to be used by your "CountRelevantItems" method you might consider it more readable to have the logic of isRelevant right there in the CountRelevantItems method rather than elsewhere in the class.