简体   繁体   中英

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.

In my example here, I'll consider the reserved word 'time'. Let's say I want to create a class 'Timepiece'. Is it not recommended to use 'timepiece' because the name begins with 'time'? Would it be recommended to use 'time_piece' or to avoid inserting the reserved word at all? 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?

How does time_piece not use a reserved word like timepiece does?

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).

Let's instead say you meant Time , which isn't a reserved word, but is an existing class. If you name something Time you're re-opening the class. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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