- Published on
[Refactoring] System construction is the same as a house that has been renovated and renovated infinitely.
Roughly speaking
- Why does programming development slow? A compilation of the complete book of Six Laws.
- Refactoring is the act of cleaning up code while maintaining existing functionality.
- Programming is based on the wisdom created by the giants of the past. They are desperate to avoid Kowloon City.
In the complete six laws, something that fixes the clause without contradiction
Programming can only be understood by programmers.
From the outside, he's a weirdo who hates meetings, who tends to slap his keyboard more than usual. He is also known for frequently fighting with sales.
Every system has a common trend, and it is becoming increasingly difficult to release new features.
Have you ever noticed? Oh, it's a similar feature than when I asked an engineer to do the previous job, but the development schedule is growing more and more.
Why does it take more time to do the same feature? There was someone who was doing a good example on Twitter.
When asked by non-programmers, "Why is it so difficult to change?", they say, "I want you to remember the six laws, find one sentence out of the clauses and check if it is contradictory to others, and of course, the client doesn't know what clauses to change, so please look into them all there is to it."
This is easy to understand. The complete books of the Six Laws must not be contradictory. If there is even one system, all of it will not work. Progress is always zero or no. It's either moving or not moving.
In the past, architectural illustrations were often used. Personally, the architecture analogy fits me best. System development is a virtual architecture that utilizes the wisdom of past great people. It's worse than architecture because it's virtual, but it's difficult for other people to understand the situation.
Still, there are many knowledge gains from architecture. Code Complete 2nd Edition (2 volumes in total), which is said to be a must-read for engineers (of course they do), calls software development software construction (architecture), and then addresses the Tacoma Strait Bridge, a bridge that no one could cross due to a design error.
This is a disaster caused by design errors, but if the creators of the systems, such as Seven Pay and Docomo accounts, have become hotbeds of problems, from all perspectives, even if they look at it, it will become a clump of garbage.
So what can be done to prevent the system development from slowing down is refactoring.
What is refactoring that I want business sides to know?
What is refactoring? This is an action that involves modifying the code to "easy to understand and modify" without changing the overall functionality of the program. The key is that no new features are added.
Anyone who has written code before experiences it, but no matter how beautiful the code is written, if you stand for a while and look back, you'll find that you don't know what you're doing. No one can remember everything perfectly, let alone code written by others.
Refactoring exists to facilitate understanding and modification of the code. It's safe to say, but programming techniques exist mostly to solve this.
When you often greet people called super programmers in your organization, you may not be able to work well. This is because the refactoring element is missing, and code that only the person can understand remains like a secret sauce and stumps. To prevent this, refactoring must be performed periodically.
One thing I want business side to understand is that there are things that systems need to stop. It is almost impossible to refactor while adding new features. Of course, as a professional, I understand business goals as fast as possible, but even so, if we don't stop developing new systems' new features, everything will collapse, so I warn that we need to stop development as a professional.
Since I'm going to do this, I'll give you some examples. This is a method called function extraction. This book is written in the first edition of the book, the second edition (ES6 in JavaScript) introduced this time, and you may want to read one of the familiar ones (both the first edition and the second edition have their own advantages).
Function extraction is an attempt to make a piece of code that performs a particular function into an independent function with a suitable name for its purpose. The diagram below shows the code for issuing a receipt. Can you tell from the difference between before and after that the code itself begins to convey its intent?
- before (Order details are output for each product)
function printRecipt(order) {
for (const item of order.items) {
// Output details to log
console.log(item.price);
console.log(item.amount);
console.log("--Total Amount-----");
// Output the total amount
console.log(order.item.price * order.item.amount);
}
}
- after (make sure that the item and total amount are independent as separate functions. You can declaratively write that the item and total amount must be written on the receipt)
function printRecipt(order) {
for (const item of order.items) {
// Output details to log
printDetail(item);
// Output the total amount
printSum(item);
}
}
// Output details
function printDetail(item) {
console.log(item.price);
console.log(item.amount);
}
// Output the total amount
function printSum(item) {
console.log("--Total Amount-----");
console.log(item.price * item.amount);
}
By the way, it's even easier to write. I reviewed the for statement and wrote printSum inside printDetail to bring the call together. This is a pattern that focuses on the amount of code, and is grateful that it reduces the amount to be understood.
- after2(inline for statement)
function printRecipt(order) {
order.items.map((item) => printDetail(item));
}
// Output details
function printDetail(item) {
console.log(item.price);
console.log(item.amount);
// Output the total amount
printSum(item);
}
// Output the total amount
function printSum(item) {
console.log("--Total Amount-----");
console.log(item.price * item.amount);
}
This accumulation of each and every improvement makes the huge system possible to maintain.
Our virtual house on the shoulder of a giant
The system is a virtual home and a virtual Sagrada Familia, built on top of the library left behind by all our ancestors.
If you let your guard down and repeat the construction properly, it will become a cruel Kowloon City in Hong Kong.
The only way to clean this from scratch is to rebuild the system. In fact, all of the Kowloon City listed below have also been demolished and is now a park.
Refactoring is the path that all engineers should take. Regardless of engineers, I would recommend reading it for business people who want to understand programming. The light-hearted phrases typical of technical books will become addictive.