官术网_书友最值得收藏!

What Is Refactoring?

Let's Define It

Refactoring is just a fancy term that means improving your code without changing how it behaves.

If improving the quality of your code introduces more bugs or changes how the system worked before, then is it really improving your code? Nope!

With refactoring, the best approach is to apply small targeted changes to a code base. Instead of making a huge sweeping change to your code, refactoring is better as a long-term, continuous enterprise.

Why? Applying larger changes all at once presents more risk and more time to implement.

We don't want that.

We want to improve the health of our code while maintaining control of our code/software.

Note

It's important to have your code under test (unit, integration, and so on) as this will give you a safety net to ensure any code changes won't also change its behavior and cause bugs.

While we won't look at building tests in this book, it's important to remember the importance of having tests.

Our Approach

I've found that many refactoring resources are hard to follow and easily overwhelming. They also tend to start at the wrong end by telling you what a pattern is before explaining what problem it solves.

Each category/section in this book represents some kind of code smell. A code smell is some indication that a part of your code is rotting and becoming unhealthy.

The first section of each category will introduce how to identify a specific code smell and why it is considered unhealthy. Then, we'll look at techniques that can be used to address the code issue – after we've explored the problem first!

Design Patterns

When learning about design patterns (https://en.wikipedia.org/wiki/Software_design_pattern), it's important to realize that these patterns are a form of refactoring tool.

Design patterns are meant to address issues around the fact that your code is not flexible enough, hard to maintain, and so on.

As you move through this book, the emphasis will be on looking at and solving specific code issues. Some of those issues just happen to be solvable using design patterns!

主站蜘蛛池模板: 英吉沙县| 华蓥市| 绩溪县| 河津市| 洪洞县| 邵武市| 成都市| 遂宁市| 芦溪县| 启东市| 台州市| 高碑店市| 阿拉尔市| 怀集县| 大庆市| 修文县| 井冈山市| 和静县| 江陵县| 呼图壁县| 绍兴县| 大理市| 莱西市| 砚山县| 兴城市| 三门峡市| 海原县| 海伦市| 洛川县| 鞍山市| 芦山县| 开江县| 墨脱县| 巴里| 杂多县| 麻栗坡县| 临西县| 兴城市| 涞水县| 勃利县| 绥化市|