4 ms·
snake_case for life!
by onebot 5y ago
snake_case for life!
- edent 5y agoYes! I found that really interesting. It bemuses me that studies show $VariableName is more readable than $variable_name!
- NateEag 5y agoThere is at least one study that supports snake case being more readable: http://ieeexplore.ieee.org/xpl/articleDetails.jsp?reload=true&tp=&arnumber=5521745 http://ieeexplore.ieee.org/xpl/articleDetails.jsp?reload=tru...
- _dain_ 5y ago>One main difference is that subjects were trained mainly in the underscore style and were all programmers. so in this study, where the subjects were trained in snake_case, they found snake_case was better. and in the other study, where the subjects were trained in camelCase, they found camelCase was better. I bet if we did another study of programmers who used kebab-case they'd find that kebab-case is better. I don't think there's any reason to believe any particular case style is better than any other. personally I like snake_case and kebab-case because I find the word boundaries easier to recognize, but that's just a preference on my part. I have no idea if it's objectively better.
- NateEag 5y agoYeah, none of the study results I've seen have been strong. I don't trust them all that much. I prefer snake_case and believe it probably is mildly more readable than camelCase. The underscore comes closer to space-delimited words like we use in English, typographically speaking. It's hard for me not to think that must be easier to read that way. Obviously I can't prove it's better, but it both makes sense to me that it would be and fits with my subjective experience.
- jpcfl 5y agoStudies show CamelCase is easier to type, which is what the book references. But, studies also show that snake_case is easier to read. Code will be read more than it will be written, so it should be optimized for the reader.
- edent 5y agoThe study referenced - https://ieeexplore.ieee.org/abstract/document/5090039 https://ieeexplore.ieee.org/abstract/document/5090039 - says that coders and non-coders find CamelCase easier to read. But I'm eager to find counter examples.
- gls2ro 5y agoI cannot access the study, but I find it odd that they say in abstract: > Results indicate that camel casing leads to higher accuracy among all subjects regardless of training, and those trained in camel casing are able to recognize identifiers in the camel case style faster than identifiers in the underscore style. What does it mean: > those trained in camel casing are able to recognize identifiers in the camel case style faster than identifiers in the underscore style. It is not normal if you train in reading something => you are good in recognizing that things that you are trained than something else than you did not train for? If anyone has access to the study, how many among 135 are programmers that were trained in camel case and how many in snake case?
- drakmaniso 5y agoIt's more complicated than that. The study referenced in the book found that snake_case makes variables easier to read, but the whole program harder to parse (my guess is it's because of the visual similarity between the underscore and a space). With camelCase, it's the other way around. I vote for kebab-case, but I didn't find any study where it was included...
- _dain_ 5y agois it easier to type? I can give an objective reason why kebab-case may be easier to type: you don't have to press shift at any point.
- factotvm 5y agoI'm here for this, but not to declare empathically my position. Rather, I'd like to ask a question: Say I'm learning a new language that is opinionated about casing. Suppose it was easier to read one style, but the language in question adopted another style. Would you buck the trend of that ecosystem and adopt it, or follow convention?
- pmontra 5y agoYou follow convention because the other developers have to read and work with your code. You also follow the formatting conventions of the language and of the project. As a polyglot developer it feels a little weird but it can't be helped. The mix of camel cased and snaked cases languages in the same project or in the same file is inevitable sometimes. Think a JS script tag and Ruby <% %> inline code in an html.erb file.
- rmk 5y agoMeh. Really depends on the language. You'd be like a fish out of water if you stuck to that convention in Javascript or Go, whereas you'd be perfectly conventional in Python and C.
- ok123456 5y agoI just do what my linter tells me.