I really do not code bug, wait, first try rubber duck debugging

In order to test the students today to finish the work, I work overtime to test the function.

Because my code is finished, there is no need to accompany test, so it can not go ~

In the afternoon the first question put over a rule of thumb, this should be a logical question test, and finally he found himself.

After a while, I put a second question, saying that this is the hit of the conditions for entering a certain level, do not enter, skip to the next level.

I have several years of development experience, certainly not at this time say "my code is not bug, you try again." To say that the cost is almost zero, but if the fight face it, that's really hurt ~ ~ ~

Under the mind to think quickly discovered not by the mind exercises can give an answer, so obediently, open the computer cover, fingerprint to unlock, connect VPN, view the log, go.

Because of this demand indicators giant, the process is relatively long, so I have printed the log data in the key nodes of the code.

So, you want the information, logs are there. But, carefully read the data in the log, and carefully compared the test data to test the students presented. Reason, this really should hit.

But the fact is not hit, the investigation began.

 

View Configuration Center

Because many indicators, each indicator has a threshold value, the first first reaction was someone else's pot, so I do not trust the students looked at the test is not adjusted parameter threshold in question, after reading, I am a bit guilty, this is not students test questions, indicators are right on.

But still did not give up, is not no load options as I said to him to tap the heat, leading indicators did not take effect. Thought of here, I'm a little excited, yes, I was able to surface understatement, actually excited heart to tell him the truth: this is the configuration you forget to check it (how it is, is your problem)

Want to go to, you want airs would have emboldened, emboldened you have to take evidence.

Our distribution center to do is so intimate, each operation can view the history. Quickly tap, then cut a figure, his training and preparation.

And so on, this, did not think ah, the students could be so much rigorous testing, the option is checked.

emmm

 

Adjustment strategy

From the point of view logs, test data is not a problem.

From the distribution center point of view, the configuration also on the hook.

Tests rule out suspects, only one truth, is my problem (slap at yourself, you can tap to start).

Although the family connected to the VPN, you can also look at the log, publishing projects, but local does not help to start the service, UT also ran unreasonable.

It can only look at the code, you know, knows nothing doubts nothing, find someone else drawback, it was on opening chapter Levin, a Lay a standard.

To find their own problems? First of all have to deny themselves, know that I was also flawed, this is how difficult thing, but I did it!

In order to test the students an explanation, I began to read their own code of honest attempt glance found wanting - (the South too

 

 

Unwise

Relates to a test point code logic is not complicated. Probably this is the process

Upstream concurrent call to get the current value of each index -> filter layer in the rule -> If two rule conditions hit is considered a hit, or miss

Thus, according to two indicators provides students tests and test data provide a threshold than two rules.

From the log view, the upstream data is not a problem, from the data comparison, it should be by comparison, but did not hit.

So began a careful examination of these two rules related code, to prevent, the tremor "! =" Written in the case of "==" is.

Unfortunately, in my view, more critical view of the place, we found that my code is so strict, I can not find any flaws.

In order not to test students hang draw on this thread I water, catch fish, I had to release the lock:. "Code looked nothing issue, you first test other logic, I see."

 

Small Huang Ya saved me

My mind clear, although I have a little astigmatism, but not blind eyes.

So even if more than ten times eight times, certainly still can not find the bug.

It is time to change the thinking of.

Above that, upstream of the code rule out suspected, suspected arising from either code itself excluded, of course, exclude suspects test students, let alone the downstream code downstream totally unaware ah.

Think about it, there are two rules before any other code, although also a rule. I decided to polish his eyes, looking for human flesh bug.

To himself as a machine without feelings, again reading this neat clean code I wrote, over the results of the code, to exclude suspects.

Upstream of the assignment is no problem! 
Variable initialization and return the results no problem! 
The first rule is no problem!

  

The first rule is no problem!

Other initial variable assignment and return no problem!

Then start the rules through the intermediate code between a first rule and the second rule.

It does not seem to return the expected value ah when the method returns? !

Yes, I should have hit regardless of whether or not a variable value to be returned, only to return in conditions of assignment in the hit. If you do not hit this rule, there is no assignment, the type that actually returns the default value of this variable, which is 0, the zero!

趾高气昂只会迟到,但永远都不会缺席。

我告知测试同学,我应该知道原因了,我修复下,一会再试下,后面的“英雄事迹”就不多介绍了。

 

总结盘点

虽然不是什么大问题,也不是什么线上大事故。

只是想表达,几乎没有人敢说自己写的代码0bug,写完就可以上线。曾经有跟我这么承诺和标榜的人,最终都是难逃翻车和打脸的命运。

有问题,理性分析最重要,从涉及bug的方方面面,包括经手的人和代码本身,都有可能出问题。

有时候,如果发现是自己的问题,但是又迟迟找不到原因,不要一个人闷着头苦苦思索,找个同事来帮你一起找。有时候就在你准备让别人一起来看看,你开始描述问题的诡异之处,还没说完,你就突然知道了原因。不知道你遇到过没有,反正我有。

今天回过头想想,哪些被我叫来的人其实就是工具人,他们和小黄鸭无异。

什么是小黄鸭和小黄鸭调试法呢,参见百度词条

此概念是参照于一个来自《程序员修炼之道》书中的一个故事。传说中程序大师随身携带一只小黄鸭,在调试代码的时候会在桌上放上这只小黄鸭,然后详细地向鸭子解释每行代码  。
  许多程序员都有过向别人(甚至可能向完全不会编程的人)提问及解释编程问题,就在解释的过程中击中了问题的解决方案。一边阐述代码的意图一边观察它实际上的意图并做调试,这两者之间的任何不协调会变得很明显,并且更容易发现自己的错误。如果没有玩具小鸭子也可以考虑向其它东西倾诉,比如桌上的花花草草,键盘鼠标。

  

类似这样

或者这样

找不到鸭子,找同事也一样~

 

如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!如果您想持续关注我的文章,请扫描二维码,关注JackieZheng的微信公众号,我会将我的文章推送给您,并和您一起分享我日常阅读过的优质文章。

Guess you like

Origin www.cnblogs.com/bigdataZJ/p/rubber-duck-debugging.html