- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 _
命名任何未使用的变量有一个通用规则。在 Elixir 中。这样做会阻止任何绑定(bind)到该变量的东西。
但是,我注意到一种广泛使用的模式,即使用下划线前缀来表示忽略的参数,形式为 _tail
。 (目的是提供关于变量是什么的提示)。
如果您尝试访问 _tail
,该语言会通过 shell 中的警告鼓励这样做。 :
warning: the underscored variable "_tail" is used after being set. A leading underscore indicates that the value of the variable should be ignored. If this is intended please rename the variable to remove the underscore
_tail
绑定(bind)了变量,而仅使用
_
它不是。
_
以外的任何内容命名忽略的变量时会降低性能? ?或者 Elixir 是否仍然绑定(bind)
_
在幕后,只是在任何尝试访问时出错?
_*
如
_
因此没有开销,来源:
http://erlang.org/doc/efficiency_guide/myths.html
最佳答案
鉴于每个人都已经给出了不用担心这种性能行为的免责声明,答案是:如果一个变量没有被使用,编译器会注意到它并且编译的字节码会简单地忽略它,就像你使用了 _
.这就是为什么如果你这样做 x = 1
永远不会x
,您会收到编译器警告。
关于elixir - 在 Elixir 中使用 "_var"而不是 "_"时的性能影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34487482/
我发现自己不确定是否应该将我在我的类中使用的某些变量设置为私有(private)类变量(例如 _var)与类常量变量(例如 VAR)与私有(private)类常量变量,如果这样的话使用(例如 _VAR
我正在尝试学习 C++(目前只知道 PHP 和一些 C#)并且遇到了我的第一个问题。 我试图在开关内调用一个类,然后在开关后使用该定义的变量。但是,我收到标题中描述的错误。 #include #in
这个问题在这里已经有了答案: What's the deal with a leading underscore in PHP class methods? (14 个答案) 关闭 9 年前。 PH
我最近更新到 PHP 5.3.6,其中有一些已弃用的函数和 INI 指令。我有以下功能: function ServerVar($varName) { global $HTTP_SERVER_VARS
我最近更新到 PHP 5.3.6,其中有一些已弃用的函数和 INI 指令。我有以下功能: function ServerVar($varName) { global $HTTP_SERVER_VARS
随着所有这些新的 ARC 内容(不属于 NDA...)的出现,处理属性的默认设置似乎是在实现文件中显式设置没有和 ivar 的属性,直到您将它与类似的东西合成: @synthesize var = _
我有一个类: class Impl1 : public POA_I1 { private : Impl2_var ob; public : Impl
鉴于此: fn main() { let variable = [0; 15]; } Rust 编译器产生这个警告: = note: #[warn(unused_variables)] on b
使用 _ 命名任何未使用的变量有一个通用规则。在 Elixir 中。这样做会阻止任何绑定(bind)到该变量的东西。 但是,我注意到一种广泛使用的模式,即使用下划线前缀来表示忽略的参数,形式为 _ta
我很好奇地寻找为什么在 C#.NET 设计器中不允许使用以下代码的解释: const foo f = new foo(); 它给出了以下错误信息: 'f' is of type 'ConsoleApp
这段代码: $query = array( "var" => "no", "not_var" => "yes", "var2" => "maybe" ); print http
我是一名优秀的程序员,十分优秀!