Check Your Code First Before Looking to Blame Others
来源:互联网 发布:淘宝王者代练可靠吗 编辑:程序博客网 时间:2024/05/17 07:49
Check Your Code First Before Looking to Blame Others
Allan Kelly
DEVELOPERS—ALL OF US!—often have trouble believing our own code is bro- ken. It is just so improbable that, for once, it must be the compiler that’s broken.
Yet, in truth, it is very (very) unusual that code is broken by a bug in the com- piler, interpreter, OS, app server, database, memory manager, or any other piece of system software. Yes, these bugs exist, but they are far less common than we might like to believe.
I once had a genuine problem with a compiler bug optimizing away a loop vari- able, but I have imagined my compiler or OS had a bug many more times. I have wasted a lot of my time, support time, and management time in the process, only to feel a little foolish each time it turned out to be my mistake after all.
Assuming that the tools are widely used, mature, and employed in various tech- nology stacks, there is little reason to doubt the quality. Of course, if the tool is an early release, or used by only a few people worldwide, or a piece of seldom downloaded, version 0.1, open source software, there may be good reason to suspect the software. (Equally, an alpha version of commercial software might be suspect.)
Given how rare compiler bugs are, you are far better putting your time and energy into finding the error in your code than into proving that the compiler is wrong. All the usual debugging advice applies, so isolate the problem, stub out calls, and surround it with tests; check calling conventions, shared libraries, and version numbers; explain it to someone else; look out for stack corrup- tion and variable type mismatches; and try the code on different machines and different build configurations, such as debug and release.
18 97 Things Every Programmer Should Know

Question your own assumptions and the assumptions of others. Tools from different vendors might have different assumptions built into them—so too might different tools from the same vendor.
When someone else is reporting a problem you cannot duplicate, go and see what they are doing. They may be doing something you never thought of or are doing something in a different order.
My personal rule is that if I have a bug I can’t pin down, and I’m starting to think it’s the compiler, then it’s time to look for stack corruption. This is especially true if adding trace code makes the problem move around.
Multithreaded problems are another source of bugs that turn hair gray and induce screaming at the machine. All the recommendations to favor simple code are multiplied when a system is multithreaded. Debugging and unit tests cannot be relied on to find such bugs with any consistency, so simplicity of design is paramount.
So, before you rush to blame the compiler, remember Sherlock Holmes’s advice, “Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth,” and opt for it over Dirk Gently’s, “Once you eliminate the improbable, whatever remains, no matter how impossible, must be the truth.”
- Check Your Code First before Looking to Blame Others
- Check Your Code First Before Looking to Blame Others
- do your test before you deliver your code to community
- How to check others Concurrent Request Output
- Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your My
- Isolate Your UI Code Before It Invades Your Business Layer
- Code Project - Your First C# Web Service
- 创建存储过程错误(已解决):Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server ver
- How to design your first programs
- final simple step: check before commit to repo
- Code to check Memory available on iPhone
- How to set trace for others sessions, for your own session and at instance level
- 二 How to encryption your code
- Use SVN to manage your code
- Smart Pointers to boost your code
- Smart Pointers to boost your code
- Migrating your code to Objective-C ARC
- Adding new Code to your GitHub Repository
- 第四篇:Linux文件系统的介绍(搬移自我的新浪博客)
- Git简单教程(一)--简介
- HTTP应用:模拟灌水机器人
- 子线程网络图片查看器和Handler消息处理器
- django源码分析 -- django启动初始化过程分析
- Check Your Code First Before Looking to Blame Others
- 如何学习摩斯码
- Choose Your Tools with Care
- C++ 文件读写
- android module 添加内容
- (KMP 1.4)hdu 3746 Cyclic Nacklace(使用next数组来求循环节的长度——求一个字符串需要添加多少个字符才能使该字符串的循环节的个数>=2)
- Comment Only What the Code Cannot Say
- DS之顺序表
- 代码坏味道与启发--《代码整洁之道》总结