Hi
As you aware, in .NET code-behind style, we already use a lot of function to accommodate those _Click function, _SelectedIndexChanged function etc etc. In our team there are some developer that make a function in the middle of .NET function, for example:
public void Button_Click(object sender, EventArgs e)
{
some logic here..
some logic there..
DoSomething();
DoSomethingThere();
another logic here..
DoOtherSomething();
}
private void DoSomething()
{
}
private void DoSomethingThere()
{
}
private void DoOtherSomething()
{
}
public void DropDown_SelectedIndexChanged()
{
}
public void OtherButton_Click()
{
}
and the function listed above is only used once in that function and not used anywhere else in the page, or called from other part of the solution.
They said it make the code more tidier by grouping them and extract them into additional sub-function. I can understand if the sub-function is use over and over again in the code, but if it is only use once, then I think it is not really a good idea to extract them into sub-function, as the code getting bigger and bigger, when you look into the page and trying to understand the logic or to debug by skimming through line by line, it will make you confused by jumping from main function to the sub-function then to main function and to sub-function again.
I know this kind of grouping by method is better when you writing old ASP or Cold fusion style, but I am not sure if this kind of style is better for .NET or not.
Question is: which is better when you developing .NET, is grouping similar logic into a sub-method better (although they only use once), or just put them together inside main function and add //explanation here on the start of the logic is better?
Hope my question is clear enough.
Thanks.
UPDATE: Thanks all for the answer and input so far.
Its just that we have been putting all logic and stuff into 1 function (we only have 2-3 developers before), and suddenly we growing into the team with 7-8 developers, and everyone have their own style.
I thinks its better to start building a guidelines, thats why I feel the need to ask the question.