Beware the Share
来源:互联网 发布:淘宝c店 编辑:程序博客网 时间:2024/06/05 00:43
Beware the Share
Udi Dahan
iT WAS MY FiRST PROjECT AT THE COMPANY. I’d just finished my degree and was anxious to prove myself, staying late every day going through the existing code. As I worked through my first feature, I took extra care to put in place everything I had learned—commenting, logging, pulling out shared code into libraries where possible, the works. The code review that I had felt so ready for came as a rude awakening—reuse was frowned upon!
How could this be? Throughout college, reuse was held up as the epitome of quality software engineering. All the articles I had read, the textbooks, the seasoned software professionals who taught me—was it all wrong?
It turns out that I was missing something critical.
Context.
The fact that two wildly different parts of the system performed some logic in the same way meant less than I thought. Up until I had pulled out those libraries of shared code, these parts were not dependent on each other. Each could evolve independently. Each could change its logic to suit the needs of the system’s changing business environment. Those four lines of similar code were accidental—a temporal anomaly, a coincidence. That is, until I came along.
14 97 Things Every Programmer Should Know

The libraries of shared code I created tied the shoelaces of each foot to the other. Steps by one business domain could not be made without first synchro- nizing with the other. Maintenance costs in those independent functions used to be negligible, but the common library required an order of magnitude more testing.
While I’d decreased the absolute number of lines of code in the system, I had increased the number of dependencies. The context of these dependencies is critical—had they been localized, the sharing may have been justified and had some positive value. When these dependencies aren’t held in check, their ten- drils entangle the larger concerns of the system, even though the code itself looks just fine.
These mistakes are insidious in that, at their core, they sound like a good idea. When applied in the right context, these techniques are valuable. In the wrong context, they increase cost rather than value. When coming into an existing codebase with no knowledge of where the various parts will be used, I’m much more careful these days about what is shared.
Beware the share. Check your context. Only then, proceed.
- Beware the Share
- Beware the Share
- Beware the Share
- Beware of the stopwatch
- Beware the C++ implicit conversion
- Hackers Beware: The Ultimate Guide to Network Security
- share the oracle experiences
- Beware File Open/Save Dialogs: They May Change The Current Directory
- Hackers Beware: The Ultimate Guide to Network Security by Eric Cole
- 狮子那一份the lions share
- Share: The Icon No One Agrees On
- share
- share
- share
- share
- Beware of GPU memory bandwidth!!
- Beware what you wish for
- Beware of unknown root causes
- 思考、学习新技术的原则和方式-程序员人生的精华
- F数圈圈
- Before You Refactor
- 近200篇机器学习&深度学习资料分享(含各种文档,视频,源码等)
- nginx服务器更改网站根目录
- Beware the Share
- 剑指offerr--二叉搜索树的第k个结点
- php 消息推送(含源码)
- The Boy Scout Rule
- matlab中常用函数
- C++函数(一)
- 设计模式之适配器模式
- PyQt4 - (2) 第一印象 (pyqt的入门)
- noj算法题——堡垒问题