I’m thinking of heavily using these from now on. From what I can tell, they seem amazing.
They enable me to understand what a class is actually doing much faster. If I see a local method with a good name, I couldn’t care less about the implementation, I simply know it’s used in one single location and nowhere else in the entire project. I don’t care about it being private/protected/public etc. I can just collapse it and not look at it, I know it does something to some part of the code that I don’t care at this point.
However, I want your opinion here, do they reduce readability?
Example 1
class Example
{
private void MethodA()
{
MethodB(); // Calling
void MethodB()
{
// MethodB implementation
}
}
}
If you asked me, in this example, they don’t. They are super clear and easy to understand.
But, what if we start nesting them?
Example 2
class Example
{
private void MethodA()
{
MethodB(); // Calling
void MethodB()
{
MethodC(); // Calling
void MethodC()
{
// MethodC implementation
}
}
}
}
Here I believe code readability can suffer. I still look at this as an improvement, since I know exactly what depends on what and what is used where, but it’s ugly as hell.
What’s your input on this? Do you recommend only going X levels deep or just completely avoiding these? I don’t really see a point in limiting yourself to the depth of these, since you are breaking any consistency in your code that you built up to that point.
I’d love to hear some feedback on these