Refactoring a 1000-Line Method into Clean(er) Code

30,678 بازدید
بیشتر
JetBrains
JetBrains
Long functions living in yet longer classes are common in many code bases that have been dwelling in production long enough. Eve ...
Long functions living in yet longer classes are common in many code bases that have been dwelling in production long enough. Even though every programmer knows it's wrong to write long functions, each of us has at least once initiated one such beast, or spent a part of their life feeding it with new code and keeping it alive. Instead of trying to understand why that happens, we will try to fix one such function as a demonstration of reverting this uncanny process.

In this webinar, we dissect one very long function, with around 1,000 lines of code in it. You will see what motivates us to break it into shorter functions. Then, we will start refactoring and redesigning the function using common refactoring techniques supported by the ReSharper tool.

If you like solving Sudoku, then the example will amuse you for sure. The program we will be dealing with is issuing a fresh Sudoku problem, and then solving it step by step, explaining every solution step by step in plain English. But, the very way in which this interesting program has been developed will aggravate its further development and grind it to a halt. That will be the point where this demonstration begins. If you would like to try your own wits on this example before or after the webinar, please download the full .NET source from GitHub and try to refactor it on your own: https://github.com/zoran-horvat/sudok....

0:06 - The 1000 line function
9:22 - Breaking regions into separate functions
17:20 - Using compile errors to cut code loose
25:15 - Extracting repeat code into separate functions
32:38 - Simplifying types and extracting utilities
38:48 - Understanding code and redesigning state
50:50 - Deeper object structures

This webinar was part of JetBrains .NET Day Online 2019.

About the presenter
Zoran Horvat is a Principal consultant at Coding Helmet Consultancy, public speaker, author of 100+ articles, and independent trainer focusing on the .NET technology stack. You can find him speaking at conferences and user groups, promoting the object-oriented development style, clean coding practices, and techniques that improve the longevity of complex business applications. Since 2014, Zoran has been publishing video courses, explaining object-oriented modeling and design as the central element of application design, and relating it to other development aspects, such as persistence, UI, and system integration.

همه توضیحات ...