Check Your Code First Before Looking to Blame Others

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.”

时间: 2024-10-11 17:52:05

Check Your Code First Before Looking to Blame Others的相关文章

左耳听风-ARTS-第9周(2019/06/02-2019/06/08)

Algorithm 这周的算法题是plus one(https://leetcode.com/problems/plus-one/). public int[] plusOne(int[] digits) { int i = digits.length - 1; while (i >= 0) { if (digits[i] == 9) { if (i > 0) { digits[i] = 0; i--; } else { int[] target = new int[digits.length

Learning How To Code Neural Networks

原文:https://medium.com/learning-new-stuff/how-to-learn-neural-networks-758b78f2736e#.ly5wpz44d This is the second post in a series of me trying to learn something new over a short period of time. The first time consisted of learning how to do machine

OER 7451 in Load Indicator:Error Code=OSD-04500

问题现象: 今天客户一台运行了半年的数据库远程登录始终hang住,查看数据库altert日志不断报如下错误: OER 7451 in Load Indicator :Error Code = OSD-04500: 指定非法选项 O/S-Error:(OS 1)函数不正确.! 解决办法: 07451, 00000, "slskstat: unable to obtain load information." // *Cause:  kstat library returned an er

Jenkins Xcode 证书设置错误 Code Sign error: No matching codesigning identity found: No codesigning identities

Jenkins 集成Xcode 项目的时候在证书上遇到了问题.实际上如果在本地的话.只要Xcode工程里选择了项目就不需要重新设置证书了.jenkins会自动找到这个证书,只要在build setting 里设置的是正常的.并且在xcode 里能正常编译. Check dependencies Code Sign error: No codesigning identities found: No codesigning identities (i.e. certificate and priv

OER 7451 in Load Indicator : Error Code = OSD-04500:指定了非法选项

alert 日志错误OER 7451 in Load Indicator : Error Code = OSD-04500:指定了非法选项 Sun Apr 22 11:15:51 2012 OER 7451 in Load Indicator : Error Code = OSD-04500: 指定了非法选项 O/S-Error: (OS 1) 函数不正确. ! OER 7451 in Load Indicator : Error Code = OSD-04500: 指定了非法选项 O/S-Er

[转]Clean Code Principles: Be a Better Programmer

原文:https://www.webcodegeeks.com/web-development/clean-code-principles-better-programmer/ ----------------------------------------------------------------- "My code is working well, the website I built is looking great, and my client is happy. So why

nagios-创建内存监控脚本及监控内存

客户端修改: 1.进入/usr/lib64/nagios/plugins目录下并更改脚本权限 cd /usr/lib64/nagios/plugins vim  check_memory #!/usr/bin/perl -w # $Id: check_memory 2 2002-02-28 06:42:51Z egalstad $ # Original script stolen from: # check_memory Copyright (C) 2000 Dan Larsson # hack

Content has been consumed

if(response.getEntity() != null && response.getEntity().getContent() != null) { message = IOUtils.toString(response.getEntity().getContent()); } 会报Content has been consumed错误 这个问题是多次调用HttpEntity.getContent()导致的, Entity中的内容只能读取一次, 参考如下: You can ret

How to write a robust system level service - some key learning - 如何写好一个健壮的系统级服务

Scenario: Rewriting a quartz job service. Background: The existing service logic was hardcoding every job's cron expression into xml file. This makes the debugging/tuning of each single jobs very difficult. For example. if a job runs once everyday du