3 ms·
In the past, I've used naming methods like this, and at first, it seemed really intuitive. But it becomes unnecessarily dense over time, and often results in a
by michaelchisari 15y ago
In the past, I've used naming methods like this, and at first, it seemed really intuitive. But it becomes unnecessarily dense over time, and often results in awkward readability.
I've moved instead to simply using reasonably descriptive variable names where the type is easily inferred. The extra type information isn't missed.
sZipCode = "90210"
really isn't necessary. Instead:
zipCode = "90210"
works just fine. And leaving out the type information for a variable with no repercussions is 95% of use cases for variables.
- baha_man 15y agoNo, you're talking about Hungarian notation, the guide is talking about standardised one-letter names for certain variables.
- michaelchisari 15y agoThe way I'm reading it, they're casting a wider net than Hungarian notation, but it's similar to it.
- pbreit 15y agoIt seems pretty clear to me: "Use one-letter variables"
- michaelchisari 15y agoOn re-reading, you're right. My fault for giving them the benefit of the doubt. One letter variables? I'm a little bit speechless. I don't recommend one letter variables. I don't know if I've ever seen an official style guide that has.
- adbge 15y ago> I don't recommend one letter variables. I don't know if I've ever seen an official style guide that has. Not that familiar with idiomatic Ruby, but using one letter variables as iterators in for loops (and some other things) is pretty idiomatic C: int i; for (i = 0; i < queue_size; i++) queue[i] = get_rarest_peer(t->peer_list);
- kshipley 15y agoThe key modifying phrase was "for short block/method parameters." The authors aren't advocating one letter variables throughout your code, only in situations like: [1, 2, 3].each { |e| puts e } Object.methods.each { |m| "Method is: #{m}" }
- michaelchisari 15y agoEven as such, using full words is barely any more typing, and more readable. [1, 2, 3].each { |value| puts value } Object.methods.each { |method| "Method is: #{method}" } I consider that a better habit to have than using single-character variables. And style guides should be about encouraging the best habits possible.