Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: the "@" indicates plural hence "s" is redundant

by thelenm (Vicar)
on Oct 30, 2002 at 16:52 UTC ( [id://209142]=note: print w/replies, xml ) Need Help??


in reply to the "@" indicates plural hence "s" is redundant

I can see your point, but I think my brain works differently. :-)

I write the names of arrays with a trailing "s", because seeing something like @function really throws me off. It looks like there is some sort of mismatch between the name of the variable and its plurality. To me, the "s" isn't redundant... it confirms at a glance that there are (possibly) multiple elements in the variable.

Of course, sometimes even a scalar variable can hold a reference to multiple elements (as an array reference, for example). In this case, there is no "@" to indicate plurality, so the "s" is necessary (in my mind, anyway). So, in my coding style,

  • $function contains a single element
  • $functions is probably a reference to an array containing multiple elements
  • @function is a type mismatch in my brain, so I don't use it
  • @functions is an array of multiple elements

That's not to say that either style is necessarily better. Mine just fits my brain better. I'm curious to see what other people think, as well.

-- Mike

--
just,my${.02}

Replies are listed 'Best First'.
Re: Re: the "@" indicates plural hence "s" is redundant
by bart (Canon) on Oct 30, 2002 at 23:47 UTC
    I have another reason for not using an "s": I generally write
    $x = $item[3];
    because
    $x = $items[3];
    doesn't make any sense.
      $x = $items[3];

      $x is the third element of this collection of items. No problem. Except my off by one error. ;)

      Really, in my mind, as I'm typing $items, I'm thinkink that this is a collection of items, but now I only want this [3] particular one. So keeping the "s" makes sense. YMMV

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://209142]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-16 20:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found