Programmers often do a task called refactoring. Refactoring is the task of changing the structure of source code without changing the behavior of the program. Why do they do it? That’s because refactoring makes the program easy to understand and update.

Source codes are “too much information.” We need to reduce cognitive costs to handle too much information. Programming languages have created many tools for that. The concept of (1.4.3) Module is an example. The concept of “method” is another example.

A brief explanation for people without programming experience. “Method” here does not mean “a way of doing something.” It is a block of instructions for the computer. A method has its name.

Method extraction is a type of refactoring. We take out some relevant lines of source code and make it a new method. Then give the method a name that describes its process. This activity is similar to organizing a group and making a nameplate.

Using this analogy, you may understand what a good grouping is. “These lines are conditional branches so let’s collect them.” It is not good. “These lines use the same name of variables.” It is not good. When these lines are related to each other and providing one functionality, it is good to put them together. If you can describe the functionality of the method concisely, it may be a good method.

There is no correct answer on method extraction. However, if you make a good method and give it a good name, it makes your programming easier. By giving a name, lines of source code are compressed into a single method name. You get a handle to think of it. It is similar to what I explained in (Column) Naming the pattern.

By compressing the code more and more, it became possible for humans to create large programs.

en.icon --- This page is auto-translated from [/nishio/(5.2.5.4) Group organization is similar to method extraction](https://scrapbox.io/nishio/(5.2.5.4) Group organization is similar to method extraction) using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at [@nishio_en](https://twitter.com/nishio_en). I'm very happy to spread my thought to non-Japanese readers.