保留字的最佳实践?重命名 Rails 中的变量
我经常发现我的模型/变量名称在 textmate 中突出显示为保留字 (即服务、属性等)
我担心这可能会引起麻烦,我通常将名称更改为其他名称 (service -> srvice, attr -> atr)
我在谷歌上搜索了一些关于这个主题的内容,但是搜索词有点棘手,所以我没有找到太多
关于如何重命名保留变量的最佳实践单词?例如添加下划线或其他前缀(_service、_attr)
Often I've found my model/var names highlighted in textmate as a reserved word
(i.e service, attr, etc.)
I'm afraid this might cause troubles and I usually change the name to something else
(service -> srvice, attr -> atr)
I googled a bit on the subject but the search terms are a bit tricky so I didn't find much
Is there a best practice on how to rename a variable that is a reserved word? such as prefixing an underscore or whatever (_service, _attr)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用名称更具创意或描述性...例如,我将数据库转换为有名为
type
的列的 Rails,该列是为 Rails magic 保留的,因此我将其重命名为facility_type
。它更长,但名称进一步记录了它包含的内容。在前面使用下划线或省略字母会使其可读性降低。get more creative or descriptive with the name... for example, I was converting a database to rails that had a column named
type
which is reserved for rails magic, so I renamed it tofacility_type
. It's longer, but the name further documents what it contains. Using an underscore at the front or omitting letters makes it less readable.