Explain by example, what improvements would be possible in a code as a result of
Refactoring.
Answers
But first, let’s agree on what is code refactoring! Basically, code refactoring is the process of changing a program’s source code without mAdd the binary number 111+10odifying its external functional behavior, in order to improve some of the nonfunctional attributes of the software. In other words, code refactoring is the process of clarifying and simplifying the design of existing code, without changing its behavior. Nowadays, agile software development is literally a must and agile teams are maintaining and extending their code a lot from iteration to iteration, and without continuous refactoring, this is hard to do. This is because un-refactored code tends to rot: unhealthy dependencies between classes or packages, bad allocation of class responsibilities, way too many responsibilities per method or class, duplicated code, and many other varieties of confusion and clutter. So, the advantages include improved code readability and reduced complexity; these can improve source-code maintainability and create a more expressive internal architecture.
Two of the most influential people in software development of recent times, Martin Fowler and Kent Beck wrote the book on the subject of refactoring called “Refactoring: Improving the Design of Existing Code”. I highly recommend you to read it, it is definitely worth it!
This book describes the process of refactoring and spends most of its time explaining how to do the various refactorings – the behavior preserving transformations. In this book you will find simple example that describes the whole process. There are also broader issues around refactoring, the “code smells” that suggest refactoring, and the role of testing, which you will find in this book as well. What I like the most about this book is that seventy refactorings and code refactoring techniques are described in detail: the motivation for doing them, mechanics of how to do them safely and a simple example. A common question is whether the book is still relevant and this is a good question since technology has made many advances, but according to our experience in Apiumhub and listening to other software developers, the book is still very useful. For example, the code refactoring techniques described in this book have not changed, since they are part of the fundamental use of programming languages. Another reason why you should read it is that it is written by legends of our time, by people who actually tried it first and developed the concept! There are other interesting books about this topic and you can find them here, but this one is a high priority one.