I think this is one of the most important Clean Code principles! I also like to sort the small methods in execution order, so you can read it from top to bottom like a book. It's also better to use methods and variable names instead of comments because comments are often lies.
@gui.ferreira11 ай бұрын
The sort-by-execution order is an interesting twist 🤔
@herewegotoday3 ай бұрын
I sort public methods alphabetically and private methods are in execution order as they typically just assist the public methods. It does get complicated if a private method supports more than one public method though. and yes...comments get lost and outdated very quick
@lunat3811 ай бұрын
Extract method is the most effective (and quite easy to apply) refactoring technique I think. good job as usual
@gui.ferreira11 ай бұрын
Thank you! Cheers!
@John.Oliver11 ай бұрын
For the past 30 years, I have pushed for smaller functions, and by extension, classes - long before it became "popular". Although there is, technically, a performance hit due to stack operations when pushing / popping function arguments, the clock cycle count for these operations is so small compared with the very large and complex code we write, it is negligable.
@gui.ferreira10 ай бұрын
I would even risk to say that in 2023, that type of perf gain is only a concern to 1% of us.
@John.Oliver10 ай бұрын
@@gui.ferreira I guess this shows my age! 👴
@gui.ferreira10 ай бұрын
@@John.Oliver Age is different than experience 😉
@kitsurubami9 ай бұрын
The refactor you performed is exactly how I write my code.
@gui.ferreira9 ай бұрын
You are doing a great job 😉
@Kimesh11 ай бұрын
What a great video. Very well explained and the example helps to show the benefits too. At my work we struggle with the issue of huge methods. This would be so helpful to improve that! Thank you!
@gui.ferreira11 ай бұрын
Thanks! I hope the video helps your team 😉
@raman4658 ай бұрын
Thanks for video I agree with this approach to extract method to do code clearest. My idea and response to criticism is we have a lot of small methods Code should be like good book. You should read code like book!
@gui.ferreira8 ай бұрын
That's it. It's one of the important ideas of the 4 Rules for Simple Design
@diogosilv411 ай бұрын
Great demo! Thank you!
@gui.ferreira11 ай бұрын
Glad you liked it Diogo!
@krccmsitp288411 ай бұрын
I like that.
@krccmsitp288410 ай бұрын
Known as Integration Operation Segregation Principle (IOSP) in Clean Code.
@omgCHopper11 ай бұрын
One of the reasons people give for not following this type of refactoring into smaller methods, with single responsibility, is performance. They argue that the use of smaller methods results in poorer performance. I'd love to hear this debated and teased out further, as I find smaller methods with single responsibility easier to read and maintain, but I don't have an easy way to answer the question of performance vs maintainability when it comes to this issue.
@gui.ferreira11 ай бұрын
There's an argument to be made on the performance side. However, in 2023, most languages/runtimes do an excellent job on that side. My go-to line of thought is that it will be a micro-optimization and you shouldn't sacrifice maintainability for the sake of it until it's proved you really need it.
@herewegotoday3 ай бұрын
You're totally right. That's the #1 reason I always hear for not using multiple methods. I always argue that developer performance typically matters more and has more impact to cost than hardware.