简体   繁体   English

html类的双引号

[英]Double Quotation marks for html classes

When using Rubocop, they specify to use single quotation marks rather than double quotation in possible places other than interpolation. 使用Rubocop时,他们指定在插值以外的可能位置使用单引号而不是双引号。 So what about the views of a rails app. 那么rails应用程序的视图呢? The classes in the views are written as follows, 视图中的类编写如下,

<div class="row-fluid">
</div>

Should this also be changed to single quotations? 这应该改为单引号吗? Do that have any performance change? 那有没有改变性能? I just want to know why does Rubocop prefer to use single quotation over double quotation. 我只是想知道为什么Rubocop更喜欢使用单引号而不是双引号。

TL;DR TL; DR

  1. Rubocop does not care about views. Rubocop并不关心观点。
  2. HTML is not Ruby, thus it does not even make sense to follow Ruby conventions in HTML. HTML不是Ruby,因此在HTML中遵循Ruby约定甚至没有意义。

Should this also be changed to single quotations? 这应该改为单引号吗?

Rubocop does not check views, so it's up to your preferences. Rubocop不会检查视图,因此这取决于您的偏好。

I just want to know why does Rubocop prefer to use single quotation over double quotation. 我只是想知道为什么Rubocop更喜欢使用单引号而不是双引号。

Today there is no performance difference when using single/double quotes. 今天使用单/双引号时没有性能差异

I think it is just a matter of taste. 我认为这只是一个品味问题。 I prefer to use single quotes if there is no need in double ones (interpolation). 如果不需要双引号(插值),我更喜欢使用单引号。 And it occurs to be the opinion of the majority of active members of Ruby community . 它发生在Ruby社区的大多数活跃成员意见中

  1. This is not a convention widely followed. 这不是广泛遵循的惯例。 For example I'd say that you will find more double quoted simple strings in Rails than single quoted ones (if you exclude requires which are typically single quoted). 例如,我会说你会在Rails中找到比单引号更多的双引号简单字符串(如果排除需要通常单引号的那些)。

  2. It's a rule I personally dislike because I usually do not know if a string will ever require a special character or interpolation (again except for requires). 这是我个人不喜欢的规则,因为我通常不知道字符串是否需要特殊字符或插值(除了要求之外)。 Example: 例:

     raise ArgumentError, 'Expected a string' 

    could later become: 可能后来成为:

     raise ArgumentError, "Expected a string, got #{some_arg}" 

    I dislike having to change single quotes to double quotes. 我不喜欢将单引号更改为双引号。

  3. I don't think there is much to gain with such a rule. 我不认为这样的规则会有很多好处。 If there was to be a rule, then I'd say prefer single-quoted strings for strings that should not have special characters nor interpolation (like files to require), but for everything else, I think it should be a personal choice as many policies, eg double quote only when needed, or on the contrary single quote only when needed (my preference), both make sense. 如果有一个规则,那么我会说更喜欢单引号字符串的字符串,不应该有特殊字符或插值(比如要求的文件),但对于其他一切,我认为它应该是个人选择,因为许多政策,例如仅在需要时双重报价,或者仅在需要时(我的偏好)单一报价,两者都有意义。

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

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