Code Smell
来源:互联网 发布:如何获得软件源代码 编辑:程序博客网 时间:2024/04/29 06:31
–Martin Fowler
A code smell is a surface indication that usually corresponds to a deeper problem in the system. The term was first coined by Kent Beck while helping me with my Refactoringbook.
The quick definition above contains a couple of subtle points. Firstly a smell is by definition something that’s quick to spot - or sniffable as I’ve recently put it. A long method is a good example of this – just looking at the code and my nose twitches if I see more than a dozen lines of java.
The second is that smells don’t always indicate a problem. Some long methods are just fine. You have to look deeper to see if there is an underlying problem there – smells aren’t inherently bad on their own – they are often an indicator of a problem rather than the problem themselves.
The best smells are something that’s easy to spot and most of time lead you to really interesting problems. Data classes (classes with all data and no behavior) are good examples of this. You look at them and ask yourself what behavior should be in this class. Then you start refactoring to move that behavior in there. Often simple questions and initial refactorings can be the vital step in turning anemic objects into something that really has class.
One of the nice things about smells is that it’s easy for inexperienced people to spot them, even if they don’t know enough to evaluate if there’s a real problem or to correct them. I’ve heard of lead developers who will pick a “smell of the week” and ask people to look for the smell and bring it up with the senior members of the team. Doing it one smell at a time is a good way of gradually teaching people on the team to be better programmers.
Gene Garcia put a summary of the smells from my book online.
From: http://martinfowler.com/bliki/CodeSmell.html
- Code smell
- Code Smell
- Common Code Smell
- Bad Smell Code
- code-smell-1-定义
- code-smell-4-巨类
- code-smell-2-重复代码
- code-smell-3-长方法
- code-smell-6-发散式变化
- code-smell-7-霰弹式修改
- code-smell-5-较长的参数列表
- Bad smell in code (代码的坏味道)
- The Stolen Smell
- Can you Smell the iBeacon?
- java重构文档(改造bad smell)
- refactoring--除去代码异味(bad smell)(1)
- refactoring--除去代码异味(bad smell)(2)
- Bad Smell(代码的坏味道)
- 见微知著 从Select语句看Oracle查询原理
- VC定义超大数组时,stack OverFlow的解决方法
- 不要把Mock当作你的设计利器
- linux网络编程:用C语言实现的聊天程序(异步通信)
- android线程、UI、AsyncTask
- Code Smell
- oracle中触发器中的after和before
- Smells To Refactorings
- uva143 - Orchard Trees
- oracle 行触发器与语句触发器的区别
- 22个Web在线编辑器
- oracle 临时表 解决 "表 *** 发生了变化,触发器/函数不能读"的问题
- oracle多表创建的视图insert
- Asynchronous Completion Token