简体   繁体   English

省略Ruby的指数运算符周围的空格有什么意义?

[英]What's the point in omitting spaces around Ruby's exponent operator?

I'm just curious about what the grounds are for omitting spaces around Ruby's exponent operator. 我只是想知道在Ruby的指数运算符周围省略空格的原因是什么。 Community-based Ruby coding style guide says one should use spaces around operators except the exponent operator ( ** ), ie: 基于社区的Ruby编码风格指南说,除了指数运算符( ** )之外,应该使用运算符周围的空格,即:

# bad
e = M * c ** 2

# good
e = M * c**2

I failed to find any info about the question at all. 我根本找不到关于这个问题的任何信息。

Probably to mirror the hand-written way of expressing that the exponent operator has a high precedence to the term it's associated with: 可能反映了手写的表达方式,即指数运算符具有与其相关联的术语的高优先级:

Written: 书面:

  • M xc 2 M xc 2

Code: 码:

  • M * c**2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM