Best Practice for reserved words? renaming vars in rails
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.
精彩评论