I wrote code, but I myself many times don't even understand the code i wrote. I heard people using "refactoring method" to help them to understand others' code.

I just knew a very little about refactoring. That is using the combined key Alt Shift R in eClipse, but it will automatically change all the related code & thus does not make any benefit for understand code.

So, what is "the refactoring method" (for understanding code wrote by someone else) that people talk about?

2 Answers
2

Refactoring just means making changes that improve readability but don't change the functionality of code. IDEs like eclipse will help you do it, but it doesn't have to be done automatically.

Where refactoring comes into play in understanding other people's code, is when that code is very poorly written. Say you have a 1000 line function with a lot of repetition that is very difficult to understand. Look for ways to break it up into smaller functions, remove the repetition, and find good names for those smaller functions.

Interestingly, it's usually possible to do this even if you don't understand the big picture at the start. Once you get all the noise out of the way through refactoring, then the big picture becomes easier to see.

Refactoring is not limited to using IDE commands (although they help a lot in refactoring). This is the technical definition:
"Code refactoring is the process of restructuring existing computer code – changing the factoring – without changing its external behavior." ([Wikipedia)1

Refactoring to understand code is when and while you are reading code, you try to understand the intent of the programmer and make changes to the code:

The reason this exercise helps you understand code better is that instead of just consuming the code and trying to understand the code for yourself, you are attempting to redesign the code so others can understand your code.