问题描述
在我看来,如果人们使用,Perl标记中的许多问题都可以解决:
It seems to me that many of the questions in the Perl tag could be solved if people would use:
use strict;
use warnings;
我认为有些人认为它们类似于训练轮,或不必要的并发症,这显然是不正确的,因为即使是非常熟练的Perl程序员也都使用它们.
I think some people consider these to be akin to training wheels, or unnecessary complications, which is clearly not true, since even very skilled Perl programmers use them.
似乎大多数精通Perl的人总是使用这两种编译指示,而那些从中受益最多的人却很少使用.因此,我认为在鼓励人们使用use strict
和warnings
时,有一个要链接的问题是一个好主意.
It seems as though most people who are proficient in Perl always use these two pragmas, whereas those who would benefit most from using them seldom do. So, I thought it would be a good idea to have a question to link to when encouraging people to use strict
and warnings
.
那么,为什么要使用Perl开发人员use strict
和warnings
?
So, why should a Perl developer use strict
and warnings
?
推荐答案
对于初学者来说,use strict;
(在较小程度上是use warnings;
)有助于在变量名中查找拼写错误.即使是经验丰富的程序员也会犯此类错误.一种常见的情况是在清理或重构代码时忘记重命名变量的实例.
For starters, use strict;
(and to a lesser extent, use warnings;
) helps find typos in variable names. Even experienced programmers make such errors. A common case is forgetting to rename an instance of a variable when cleaning up or refactoring code.
使用use strict; use warnings;
可以比其他方式更快地捕获许多错误,这使得更容易找到错误的根本原因.根本原因可能是需要进行错误或验证检查,而无论程序员或技术人员如何,这种情况都可能发生.
Using use strict; use warnings;
catches many errors sooner than they would be caught otherwise, which makes it easier to find the root causes of the errors. The root cause might be the need for an error or validation check, and that can happen regardless or programmer skill.
Perl警告的优点是它们很少是虚假的,因此使用它们几乎没有成本.
What's good about Perl warnings is that they are rarely spurious, so there's next to no cost to using them.
相关阅读:为什么使用my
?
Related reading: Why use my
?
这篇关于为什么要使用严格和警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!