开发者

Best Practice for reserved words? renaming vars in rails

开发者 https://www.devze.com 2023-04-08 22:26 出处:网络
Often I\'ve found my model/var names highlighted in textmate as a re开发者_StackOverflow社区served word

Often I've found my model/var names highlighted in textmate as a re开发者_StackOverflow社区served 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)


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 to facility_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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号