本文介绍了在Perl中使用无括号的子程序调用的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

根据:

我注意到很多时候,你可以在调用Perl子程序时忽略括号(例如,从最近的SO回答随机引用):

I notice that a lot of times, people use the fact that you can omit parenthesis when calling Perl subroutines (e.g., randomly quoting from a recent SO answer):

open my $fin, '<', $file;

open(my $fin, '<', $file);

使用第二个选项的主要(理想,技术) )版本?

doesn'

对我来说,总是使用圆括号主要是一个风格的选择,因为我的起源是一个C开发人员;但我想知道,如果我没有使用可选的无括号的语法作为Perl开发人员,因此我错过了一些东西。

For me, always using the parenthesis are mostly a stylistic choice due to my origins as a C developer; but I'd like to know if I'm missing something out on not using the optional parenthesis-less syntax as a Perl developer.

PS我知道完全好的原因,喜欢带括号的版本 - 例如。 的问题,或,或者优先visavi vs || 。我对此感兴趣。

P.S. I know full well the reasons to prefer the version with parenthesis - e.g. the issues with indirect object notation, or requirement to declare non-builtins before they are used without parenthesis, or issues with precedence visavi or vs ||. I'm interested in the opposite.

我不太感兴趣的答案只是说更好的风格/更可读没有任何研究支持的意见。我对技术原因感兴趣,或者备份文体差异偏好(请不要将备份与对授权的上诉或谬误。一项研究显示改进代码的速度或理解是一个证明。Perl社区中的每个人都同意或Damien Conway建议

P.P.S. I'm not greatly interested in answers merely stating "it's better style"/"more readable" without any studies backing the opinion up. I'm interested in either technical reasons to prefer parenthesis omission, or backed up stylistic difference preferences (Please don't confuse "backed up" with "appeal to authority" or "argumentum ad populum" fallacies. A study showing improvement in speed or comprehension of code is proof. "Everyone in Perl commmunity agrees" or "Damien Conway suggests this" without explaining how Damien backs this up is not).

推荐答案

我认为唯一的时间才是真正重要的,除了风格,是根据使用的很少使用的& subname

I think the only time that it actually matters, other than style, is for the rarely used &subname which according to perldoc perlsub:

&NAME;     # Makes current @_ visible to called subroutine.

当然,在某些情况下使用括号可能更容易消除歧义(无论是对于解析器还是将来阅读器),否则不使用它们可能会消除其他人的噪声;任何一个必要的程度可能是我选择一个或另一个的主要原因。

Of course, using parens might make for easier disambiguation in some cases (both for the parser and the future reader), or else not using them might remove noise in others; the degree to which either of those is necessary is probably the primary reason I would ever choose one or the other.

这篇关于在Perl中使用无括号的子程序调用的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 11:08