Java

Bryan Sant bryan.sant at gmail.com
Fri Feb 16 13:32:03 MST 2007


On 2/16/07, Shane Hathaway <shane at hathawaymix.org> wrote:
> Those long method names hurt polymorphism.  It's better to have a small
> set of short names that get used often.  Python's dict and file APIs are
> a good example; people try to reuse those method names wherever
> possible, and the result is that Python code tends to be quite
> interoperable.

Long names don't hurt polymorphism.  Polymorphism doesn't magically
discriminate against lengthy method names.  Short names are fine too.
If a short name adequately describes the method call, then the shorter
the better.

However, I prefer Java's toString over Ruby's to_s.  The former is
more readable and I don't have to guess what it's doing -- it's
spelled out in English (granted in python they are decent enough to
call it tostring as well).

Guess what these methods do:

toUpperCase
toLowerCase
getBytes
length
parseInteger
isDigit
findByName

The method names themselves communicate the actual verb action of the
method.  This is ideal in my opinion.  I even prefer C#'s WriteLine to
Java's println -- What's does a println?  Just spell it out!
printLine.

> The Java culture stops me.  When I write Java code, I am a member of the
> Java community and must behave as one, even if I disagree with some of
> the practices.

You do understand your civil rights correct?  You don't *have* to do
anything.  I highly doubt that if you created a new class and named a
method to_a instead of toArray, that the Java community Secret Service
would come a break your legs.  There are widely accepted (and good)
standards in the Java world, but the compiler isn't forcing that on
you.  If you like short names, use short names.

> I suspect you're defending the status quo.  If short names were more
> common in Java, I think you'd defend short names instead.

No, I'm defending long names as the superior way to communicate what
that method does.  Short names are only a benefit when you're not
using an IDE and you're forced by your crappy text editor to slog
through and type every bloody character you code.  Regardless of the
method name length, I never type more than two ore three characters.
So, since length doesn't effect productivity, the more clear the
naming the better (short or long).

-Bryan



More information about the PLUG mailing list