Variable and Method Name Conventions in Rails

I know that there is a Rails naming convention for variables and methods that should be written as this_is_my_variable and this_is_my_method .

However, I am currently looking more often at Python and Objective-C approaches, using for example thisIsMyVariable or thisIsMyMethod , and I also think this code looks prettier.

My question is is Python style naming convention also acceptable to Rails as a possibly more updated naming convention, or should I strictly adhere to the existing Rails naming convention?

+4
source share
1 answer

I think it would depend on who you ask. As far as I know, there are no official ruby ​​style rules, but basically everyone uses snake_case for variable names and methods, CamelCase for classes and modules, and SCREAMING_SNAKE_CASE for other constants.

A little googling gave me this question about ruby ​​style rules , which lists whole bundles of links to different (unofficial) style guides.

My personal opinion is that mixedCase just confusing and looks out of place in a ruby. I have seen this, but I always need to do at least a double trick to actually read it (and make sure that I don't actually read Java code).

Honestly, I would use snake_case in method and variable names in Python (which seems to conform to PEP8 - Naming Conventions ), and only ever use mixedCase in Java or JavaScript.

Back to you. I know people who would mixedCase in ruby ​​code, but most ruby ​​developers that I know will definitely not, and some will probably scream about it and throw things at you.

+5
source

All Articles