When is a Java method name too long?
Just for a change, a non-subjective answer: 65536 characters.
A.java:1: UTF8 representation for string "xxxxxxxxxxxxxxxxxxxx..." is too long for the constant pool
;-)
A name in Java, or any other language, is too long when a shorter name exists that equally conveys the behavior of the method.
Some techniques for reducing the length of method names:
If your whole program, or class, or module is about 'skin care items' you can drop skin care. For example, if your class is called
SkinCareUtils
, that brings you togetNumberOfEligibleItemsWithinTransaction
You can change within to in,
getNumberOfEligibleItemsInTransaction
You can change Transaction to Tx, which gets you to
getNumberOfEligibleItemsInTx
.Or if the method accepts a param of type
Transaction
you can drop the InTx altogether:getNumberOfEligibleItems
You change numberOf by count:
getEligibleItemsCount
Now that is very reasonable. And it is 60% shorter.