Suppose I have long method like this:
public void SomeLongMethod()
{
// Some task #1
...
// Some task #2
...
}
This method doesn't have any repetitive parts that should be moved to separate method or local function.
There are many people (including me) who think that long methods are code smells.
Also I don't like idea of using #region
(s) here and there is a very popular answer explaining why this is bad.
But if I separate this code into methods
public void SomeLongMethod()
{
Task1();
Task2();
}
private void Task1()
{
// Some task #1
...
}
private void Task2()
{
// Some task #1
...
}
I see the following issues:
Polluting class definition scope with definitions that are used internally by a single method and which mean I should document somewhere that
Task1
andTask2
are intended only for internals ofSomeLongMethod
(or every person who reads my code will have to infer this idea).Polluting IDE autocomplete (e.g. Intellisense) of methods that would be used only once inside the single
SomeLongMethod
method.
So if I separate this method code into local functions
public void SomeLongMethod()
{
Task1();
Task2();
void Task1()
{
// Some task #1
...
}
void Task2()
{
// Some task #1
...
}
}
then this doesn't have the drawbacks of separate methods but this doesn't look better (at least for me) than the original method.
Which version of SomeLongMethod
is more maintainable and readable for you and why?