Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

So I was currently in the middle of coding, unfortunately for me, I was in "The Zone" then I thought to myself, are my method/variable names to long?

POP out of the Zone I go!

So I came here to ask, are my method/variable names too long? You be the Judge! Bonus points to anyone who can figure out what I'm writing, although I'm sure a guru will figure it out fast!

Anyway, here are some of my method and variable names.

Methods : searchBlockedListForBlockedSquares(), isCurrentSquareNextToAtLeastOneBlockedSquare(), searchBlockedListForBlockedSquares()

Variables: isNextToBlockedSquares;

I Guess there was only one variable that seemed too long.

share|improve this question

3 Answers 3

up vote 21 down vote accepted

Your names seem okay to me in terms of length. However, the way they are named suggests that maybe some new classes are in order?

For example, instead of searchBlockedListForBlockedSquares() you could have blockedList.getBlockedSquares(). Similarly, isCurrentSquareNextToAtLeastOneBlockedSquare() becomes currentSquare.isAdjacentToABlockedSquare().

share|improve this answer
    
Adjacent was the word I was looking for! Thank you =) –  Bryan Harrington Nov 20 '10 at 6:04
    
@Bryan: You're welcome. :) –  Anna Lear Nov 20 '10 at 6:05
    
+1 for renaming :) –  Tech Jerk Nov 20 '10 at 6:06
    
A very good answer! –  Chris Nov 20 '10 at 13:20

I believe in descriptive variable names even if that means long variable names. And with intellisense getting more popular, I don't believe it affects much in terms of productivity.

I hate abbreviations because they are nearly impossible to consistently use. Plus, they can be ambiguous and they do make things more difficult to read. Even when they are part of a standard, I don't like them. Plus, when it comes down to it, they don't remove that many letters unless you abbreviate a lot. And abbreviating a lot kills readability.

The biggest problem long names introduces though is how long lines of code can become. Calling a function with a long name and passing it two or three long variable names can make for one long line of code. Because of that, I do try to keep my names as short as possible though again, I'd rather have descriptive names even if it means wrapping lines or scrolling.

Looking at your example names though, the fact that all end with BlockedSquares makes me think that part of the name might be redundant. In fact, it might also mean that these items can be encapsulated into their own class, probably named BlockedSquares. That change that makes the names quite a bit shorter.

share|improve this answer

A variable name is the wrong length when it is not clearly describing it's purpose. That applies to being too short or too long.

Short and terse variable names can be ambiguous, or worse have no relationship to what the variable is. In the days of interpreted BASIC, we were limited by the interpreter to two character names. It was very difficult to come up with meaningful names in a large program. Single letter variable names are often used for for-loops and counters, but I think they should be avoided otherwise. for (i = 0; i < 10; i++) {...} uses i and that's pretty common. j is a secondary variable name.

Long variable names are too long when they become long-winded or full of empty words, making them longer than necessary. If I have a bunch of similarly named variables I'll try to remove the common parts that are dispensable and keep the uniquely identifying parts of the names.

I'd have named "isCurrentSquareNextToAtLeastOneBlockedSquare" to currentSquareNextToBlockedSquare?, if I was doing it in Ruby.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.