Are short abbreviated method/function names that don't use full words bad practice or a matter of style?
Posted
by
Alb
on Programmers
See other posts from Programmers
or by Alb
Published on 2011-02-11T21:34:12Z
Indexed on
2011/02/12
7:32 UTC
Read the original article
Hit count: 244
Is there nowadays any case for brevity over clarity with method names?
Tonight I came across the Python method repr()
which seems like a bad name for a method to me. It's not an English word. It apparently is an abbreviation of 'representation' and even if you can deduce that, it still doesn't tell you what the method does.
A good method name is subjective to a certain degree, but I had assumed that modern best practices agreed that names should be at least full words and descriptive enough to reveal enough about the method that you would easily find one when looking for it. Method names made from words help let your code read like English.
repr()
seems to have no advantages as a name other than being short and IDE auto-complete makes this a non-issue. An additional reason given in an answer is that python names are brief so that you can do many things on one line. Surely the better way is to just extract the many things to their own function, and repeat until lines are not too long.
Are these just a hangover from the unix way of doing things? Commands with names like ls
, rm
, ps
and du
(if you could call those names) were hard to find and hard to remember. I know that the everyday usage of commands such as these is different than methods in code so the matter of whether those are bad names is a different matter.
© Programmers or respective owner