Another formatting question: Short variable names

View: New views
10 Messages — Rating Filter:   Alert me  

Another formatting question: Short variable names

by Bill Venners-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All,

How do people feel about hd for variables that will hold the head of a
list, ls for list, etc. What about pred for predicate? Seems if there
are some very commonly used variable names like that it could make
things more readable, but head and list are just two characters longer
each, so I question whether that wouldn't make code more readable in
general.

Dave Astels once said, whatever you would answer when asked what a
particular variable is, that is what you should name that variable.
Sometimes that approach can result in long variables that can obscure
the logic, and I think sometimes an abbreviation makes things more
readable. But I seem to lean more towards longer more descriptive
variable names than others in my sphere of peers. When would you
shorten or abbreviate a variable name, and how short would you go?

Bill
----
Bill Venners
Artima, Inc.
http://www.artima.com

Re: Another formatting question: Short variable names

by nuttycom :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

head/list

Any time variable names are abbreviated I have to mentally do the
expansion anyway. Why force the extra effort when you're talking about
two characters?

On Wed, Jun 10, 2009 at 4:46 PM, Bill Venners<bill@...> wrote:

> Hi All,
>
> How do people feel about hd for variables that will hold the head of a
> list, ls for list, etc. What about pred for predicate? Seems if there
> are some very commonly used variable names like that it could make
> things more readable, but head and list are just two characters longer
> each, so I question whether that wouldn't make code more readable in
> general.
>
> Dave Astels once said, whatever you would answer when asked what a
> particular variable is, that is what you should name that variable.
> Sometimes that approach can result in long variables that can obscure
> the logic, and I think sometimes an abbreviation makes things more
> readable. But I seem to lean more towards longer more descriptive
> variable names than others in my sphere of peers. When would you
> shorten or abbreviate a variable name, and how short would you go?
>
> Bill
> ----
> Bill Venners
> Artima, Inc.
> http://www.artima.com
>

Re: Another formatting question: Short variable names

by nuttycom :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'll amend that - I could see abbreviating "list" to "l" - just not to
"ls" because of the collision with ls.

On Wed, Jun 10, 2009 at 6:47 PM, Kris
Nuttycombe<kris.nuttycombe@...> wrote:

> head/list
>
> Any time variable names are abbreviated I have to mentally do the
> expansion anyway. Why force the extra effort when you're talking about
> two characters?
>
> On Wed, Jun 10, 2009 at 4:46 PM, Bill Venners<bill@...> wrote:
>> Hi All,
>>
>> How do people feel about hd for variables that will hold the head of a
>> list, ls for list, etc. What about pred for predicate? Seems if there
>> are some very commonly used variable names like that it could make
>> things more readable, but head and list are just two characters longer
>> each, so I question whether that wouldn't make code more readable in
>> general.
>>
>> Dave Astels once said, whatever you would answer when asked what a
>> particular variable is, that is what you should name that variable.
>> Sometimes that approach can result in long variables that can obscure
>> the logic, and I think sometimes an abbreviation makes things more
>> readable. But I seem to lean more towards longer more descriptive
>> variable names than others in my sphere of peers. When would you
>> shorten or abbreviate a variable name, and how short would you go?
>>
>> Bill
>> ----
>> Bill Venners
>> Artima, Inc.
>> http://www.artima.com
>>
>

Re: Another formatting question: Short variable names

by Blair Zajac :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bill Venners wrote:
> Hi All,
>
> How do people feel about hd for variables that will hold the head of a
> list, ls for list, etc. What about pred for predicate? Seems if there
> are some very commonly used variable names like that it could make
> things more readable, but head and list are just two characters longer
> each, so I question whether that wouldn't make code more readable in
> general.

If you're going to go short and this is for a since method, then h = head, t =
tail and p = predicate.

Blair

Re: Another formatting question: Short variable names

by Erik Engbrecht :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Real programmers only need x, y, z, i, j, k, and temp.

On Wed, Jun 10, 2009 at 6:46 PM, Bill Venners <bill@...> wrote:
Hi All,

How do people feel about hd for variables that will hold the head of a
list, ls for list, etc. What about pred for predicate? Seems if there
are some very commonly used variable names like that it could make
things more readable, but head and list are just two characters longer
each, so I question whether that wouldn't make code more readable in
general.

Dave Astels once said, whatever you would answer when asked what a
particular variable is, that is what you should name that variable.
Sometimes that approach can result in long variables that can obscure
the logic, and I think sometimes an abbreviation makes things more
readable. But I seem to lean more towards longer more descriptive
variable names than others in my sphere of peers. When would you
shorten or abbreviate a variable name, and how short would you go?

Bill
----
Bill Venners
Artima, Inc.
http://www.artima.com



--
http://erikengbrecht.blogspot.com/

Re: Another formatting question: Short variable names

by Jorge Ortiz-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hogwash!

Real programmers use tmp

--j

On Wed, Jun 10, 2009 at 8:37 PM, Erik Engbrecht <erik.engbrecht@...> wrote:
Real programmers only need x, y, z, i, j, k, and temp.

On Wed, Jun 10, 2009 at 6:46 PM, Bill Venners <bill@...> wrote:
Hi All,

How do people feel about hd for variables that will hold the head of a
list, ls for list, etc. What about pred for predicate? Seems if there
are some very commonly used variable names like that it could make
things more readable, but head and list are just two characters longer
each, so I question whether that wouldn't make code more readable in
general.

Dave Astels once said, whatever you would answer when asked what a
particular variable is, that is what you should name that variable.
Sometimes that approach can result in long variables that can obscure
the logic, and I think sometimes an abbreviation makes things more
readable. But I seem to lean more towards longer more descriptive
variable names than others in my sphere of peers. When would you
shorten or abbreviate a variable name, and how short would you go?

Bill
----
Bill Venners
Artima, Inc.
http://www.artima.com



--
http://erikengbrecht.blogspot.com/


Re: Another formatting question: Short variable names

by Ben Hutchison-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bill Venners wrote:
> Hi All,
>
> How do people feel about hd for variables that will hold the head of a
> list, ls for list, etc. What about pred for predicate? Seems if there
>  
I prefer head, list and predicate, but 'pred' is more acceptable than
'hd' or 'ls'.
> Dave Astels once said, whatever you would answer when asked what a
> particular variable is, that is what you should name that variable.
>  
That's a nice heuristic. I prefer longer names and feel anything up to
about 7-10 chars in length should be written out in full. As the length
increases, abbreviation becomes more appropriate and almost mandatory
beyond 20 chars .

However convention establishes some shorter forms, eg x and xs for
pieces of lists, f and g for opaque function values.

-Ben

> Sometimes that approach can result in long variables that can obscure
> the logic, and I think sometimes an abbreviation makes things more
> readable. But I seem to lean more towards longer more descriptive
> variable names than others in my sphere of peers. When would you
> shorten or abbreviate a variable name, and how short would you go?
>
> Bill
> ----
> Bill Venners
> Artima, Inc.
> http://www.artima.com
>  


--

       

*Ben Hutchison
Senior Developer
* Level 2 476 St Kilda Road Melbourne VIC 3004
T 613 8807 5252 | F 613 8807 5203 | M 0423 879 534 |
www.ibsglobalweb.com <http://www.ibsglobalweb.com/>



Re: Another formatting question: Short variable names

by Trond Olsen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

mkString?

On Thu, Jun 11, 2009 at 2:47 AM, Kris Nuttycombe <kris.nuttycombe@...> wrote:
head/list

Any time variable names are abbreviated I have to mentally do the
expansion anyway. Why force the extra effort when you're talking about
two characters?

On Wed, Jun 10, 2009 at 4:46 PM, Bill Venners<bill@...> wrote:
> Hi All,
>
> How do people feel about hd for variables that will hold the head of a
> list, ls for list, etc. What about pred for predicate? Seems if there
> are some very commonly used variable names like that it could make
> things more readable, but head and list are just two characters longer
> each, so I question whether that wouldn't make code more readable in
> general.
>
> Dave Astels once said, whatever you would answer when asked what a
> particular variable is, that is what you should name that variable.
> Sometimes that approach can result in long variables that can obscure
> the logic, and I think sometimes an abbreviation makes things more
> readable. But I seem to lean more towards longer more descriptive
> variable names than others in my sphere of peers. When would you
> shorten or abbreviate a variable name, and how short would you go?
>
> Bill
> ----
> Bill Venners
> Artima, Inc.
> http://www.artima.com
>


Re: Another formatting question: Short variable names

by Michael Campbell-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ben Hutchison wrote:
> Bill Venners wrote:
>> Hi All,
>>
>> How do people feel about hd for variables that will hold the head of a
>> list, ls for list, etc. What about pred for predicate?

> However convention establishes some shorter forms, eg x and xs for
> pieces of lists, f and g for opaque function values.

+1 to this.  My domain work is mainly in financial software so I often use
"acct", "pmt", etc. for Account and Payment related entities.

That said, I'm a big "NAMES ARE IMPORTANT" guy and too often we, as programmers,
tend to rely (too much) on our ability to do quick mappings of "what this is" to
"what this means".   As I get older, I prefer to do less of that and have been
really trying to name things what they are.  I see the biggest offenders of
relying on their ability are the younger and less experienced programmers; or
maybe that should be less wizened/lazy?  =)

However, as Ben mentioned, some conventions bypass the mapping altogether -
"acct" means "account" to me every bit as much as "account" does.

Re: Another formatting question: Short variable names

by Walter Smith :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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