简体   繁体   English

Rails保留字和约定

[英]Rails reserved words and convention

After having spent a lot of time researching Rails reserved words and implementing, I still have a few questions regarding use. 在花了很多时间研究Rails保留字并实现之后,我仍然对使用有一些疑问。

In my example here, I'll consider the reserved word 'time'. 在这里的示例中,我将考虑保留字“时间”。 Let's say I want to create a class 'Timepiece'. 假设我想创建一个类“ Timepiece”。 Is it not recommended to use 'timepiece' because the name begins with 'time'? 是否不建议使用“钟表”,因为名称以“ time”开头? Would it be recommended to use 'time_piece' or to avoid inserting the reserved word at all? 建议使用“ time_piece”还是完全避免插入保留字? My question here is also about use of the exact reserved word within the class like that. 我的问题也是关于在此类中使用确切的保留字。

Thank you. 谢谢。

How is time a reserved word? time如何保留字?

How does time_piece not use a reserved word like timepiece does? 如何time_piece不喜欢使用保留字timepiece呢?

In any case, name your classes what they should be named: there's no reason, technical, cultural, semantic, or otherwise, not to use a reserved word inside a class or variable name, even if Time was the same as time (it isn't) and time was reserved (AFAIK it isn't). 无论如何,给您的类命名应使用的名称:没有理由,技术,文化,语义或其他原因,即使Timetime相同,也不要类或变量名中使用保留字。 't),并且time已保留(不是AFAIK)。

Let's instead say you meant Time , which isn't a reserved word, but is an existing class. 我们不是说你的意思是Time ,这是不是保留字, 现有类。 If you name something Time you're re-opening the class. 如果您命名“ Time您将重新开始上课。 If you name something with Time in it it's entirely unrelated to Time itself, and whether or not you should use it as part of the name has more to do with semantics than anything else: again, no reason not to. 如果您其中使用Time命名则与Time本身完全无关,并且是否应将其用作名称的一部分与语义有关的比什么都重要:再次,没有理由不这样做。

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

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