This question already has an answer here:
I'm currently reading Robert Martin's Clean Code book. So far I'm enjoying it.
Martin talks a lot about separating long functions into short functions, each doing exactly one thing at one level of abstraction.
Generally I like the idea and I understand the concept and the benefits. But I have a simple question to ask:
How is taking a logical piece of code an extracting it to a new method, different than simply 'folding' it? Most modern IDEs feature code-folding.
The advantage of code-folding is that when you need to look at that logical piece of code, you don't have to scroll up and down to find it. You just press a button and it's right there in front of you, in it's linear place.
Extracting small logical pieces of code to new methods, means that when a programmer wants to look at the method you extracted, they usually have to go scrolling up and down the page for it. That's very annoying and makes it harder to concentrate.
I agree with most of what Uncle Bob writes in his book, and I really want to agree with this point. But with code-folding a part of most modern IDEs, I can't find a real reason for this idea.
Please explain the advantages of extracting small logical pieces of code to new methods, as opposed to simply code-folding them.
(I remember there was another question on this site regarding this, but it was less focused, and the answers havn't satisfied me).