« Return to Thread: Another formatting question: Short variable names

Re: Another formatting question: Short variable names

by Walter Smith :: Rate this Message:

Reply to Author | View in Thread

Bill Venners-3 wrote:
When would you shorten or abbreviate a variable name, and how short would you go?
For variable names as for class, method, or any other names, I'm using full names by default... the camel case expansion in Eclipse is such a great help that I can't see any reason not to when typing. And for reading I find longer names way more helpful, too. The only exceptions are abbreviations that are more commonly used than the full form, like html or xml. For some very mathematical algorithms I also prefer the abbreviations I'm used to from that background, like p and q, and f and g for functions.

But these are exceptions! I find hd or ls just ugly and too much to think about. But I'm using Java most of the time, and a larger community with a common language develops it's own language culture, natural or programming languages alike. It's more important that this does happen than to what end it does. E.g. in Java most comparisons are done "in reverse" like "martin".equals(name) in order to check the nullness of the variable as well; I found it funny to see this idiom to pass along into JUnit assertEquals methods, where the expected value comes first! The Java culture develops, though: The current JUnit versions use Hamcrest that tries to mimic English sentences... so it the more natural ordering of assertThat(actualValue, is(expectedValue)).

I don't like xs either, but this seems to become part of the Scala culture, and I will adopt it.

Walter

 « Return to Thread: Another formatting question: Short variable names