You wont find a single project where long method code smell is not present. I find often this code smell often in my projects, and developers do not deliberately introduce long methods, it just got introduced along the way when we introduce features.
What happen when you find a long method?
- You wonder why is this method is so long.
- You try to understand what the code is doing.
- You start hate the software because its full of lines after line but no end of the method.
- You lost the track where you ware before.
- And so on.
You can list hundreds of line like the above listing about long method, the story will go on and on. here is what “Wikipedia” has to say about the long method,
“Long method: a method, function, or procedure that has grown too large.”
Bellow an example of a long method is given
Bellow a edited version of the code is given. where the code is refactored with extract method and looks more understandable, even though you can refactor the code to a much simpler version, but this is given there as an example.
There are lot of refactoring tips and techniques to handle long method, and this is just the tip of the iceberg, this is just an example you can do many things and there are huge possibilities. Until next time me Md. Masudur Rahman Signning out.