到行代码catch语句的很好的比例 [英] Good ratio of catch statements to lines of code

查看:196
本文介绍了到行代码catch语句的很好的比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有拇指任何规则,以你多少catch语句每个代码源行期望在一个大的软件?

Are there any rules of thumb as to how many catch statements you'd expect per source line of code in a large piece of software?

例如,一条用C#编写的软件,Visual Studio中显示了包含单词约350线捕获,并 CLOC 我们对160K SLOC报道,30K注释行,和15K空行。 160K / 350是每个catch语句代码大约467行。

For instance, in one piece of software written in C#, Visual Studio shows up about 350 lines containing the word "catch", and cloc reports that we have about 160k SLOC, 30k commented lines, and 15k blank lines. 160k/350 is roughly 467 lines of code per catch statement.

不过,要与一粒盐,因为我们使用标准的C#与自己的线括号格式化,所以谁知道有多少行都只是单一的括号出来的160K,而160K是指在不再到应用程序编译树计数的一些文件,等等。我可能已经猜到了有用的比例更接近每400 LOC 1陷阱。

But take that with a grain of salt, because we use standard C# formatting with braces on their own lines, so who knows how many lines are just single braces out of the 160k, and that 160k is counting some files in the tree that are no longer compiled in to the application, etc. I might guess the "useful" ratio to be closer to 1 catch per 400 LOC.

至少不会令我惊讶,我们缺少被陷入在一个空的catch块半临界例外,所以现在我要通过代码库和至少打印出异常调试控制台作为一项临时措施,或成为捕捉到的异常更具体。当然,这会增加我们在整个应用程序捕获的数量,但它带给我们的任何地方更接近可接受区?我不知道,如果每467 LOC 1美中不足的是不错,只是还行,或者甚至是可怕的。

At least not to my surprise, we were missing a semi-critical exception that was getting caught in an empty catch block, so now I'm going through the code base and at least printing out the exception to the debug console as a temporary measure, or becoming more specific on the exception caught. This will of course increase the number of catches we have in the whole application, but will it bring us anywhere closer to the "acceptable" zone? I have no idea if 1 catch per 467 LOC is good, just okay, or horrible even.



我很清楚的为什么的不要用空的catch块。其他/先前的维护者一直偷懒。而且,由于该产品的下一个版本就是一次关键的,我目前没有时间去和妥善解决所有300(?)抓差陈述和验证软件的正常运行(当然,我们几乎没有自动化测试为了更轻松:/)


I'm well aware of why not to use empty catch blocks. The other/previous maintainers have been lazy. And since the next release of this product is time-critical, I don't currently have the time to go in and properly fix all 300(?) poor catch statements and verify proper operation of the software (of course we have virtually no automated testing to make that easier :/ ).

我只是在寻找是否有任何形式的直觉作为一个应该怎么经常看到尝试副渔获物。有一对夫妇的答案说这是上下文敏感的,这是我有点怀疑,但不知道的。

I was just looking for if there was any kind of "gut feel" as to how frequently one should see try-catches. There's a couple answers saying it's context-sensitive, which is what I kind of suspected but was not sure of.

推荐答案

这是非常很难给一个普通的数字 - 它真的会取决于何种应用是为了做以及是否需要执行在可恢复的方式也无法运作

It's very hard to give a general figure - it will really depend on what the application is meant to be doing and whether it needs to perform operations which may well fail in a recoverable way.

大点带走的是空的catch块是一个非常,非常糟糕的主意。这比每catch块行代码更重要。

The big point to take away is that empty catch blocks are a really, really bad idea. That's much more important than lines of code per catch block.

这篇关于到行代码catch语句的很好的比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆