[Israel.pm] Re: Variable Naming

Shlomi Fish shlomif at iglu.org.il
Mon Jun 7 11:14:13 PDT 2004


On Monday 07 June 2004 19:18, Uri Bruck wrote:
> Shlomi Fish wrote:
> > Right. BTW, why are you using CamelCase for variable names? Most people
> > use words_separated_by_underscore. (and I personally find it much more
> > desirable).
>
> This is the kind of comment I don't find very useful.
> First, how do you know that most people use underscores rather than
> CamelCase?

Most scripts and modules I've seen use this style almost consistently. Also, I 
also commented that I found it was more desirable. 

>
> Even if we accept this for a moment as factual, does that mean that's
> it's better?
>

You are right - it does not necessarily mean that it's better. However to 
quote from "perldoc perlstyle":

<<<
      ·   While short identifiers like $gotit are probably ok, use under-
           scores to separate words.  It is generally easier to read
           $var_names_like_this than $VarNamesLikeThis, especially for non-
           native speakers of English. It's also a simple rule that works con-
           sistently with VAR_NAMES_LIKE_THIS.

           Package names are sometimes an exception to this rule.  Perl infor-
           mally reserves lowercase module names for "pragma" modules like
           "integer" and "strict".  Other modules should begin with a capital
           letter and use mixed case, but probably without underscores due to
           limitations in primitive file systems' representations of module
           names as files that must fit into a few sparse bytes.
>>>

I may have expressed myself incorrectly. Sorry in that case.

However, I do thing it is generally a good idea to follow the programming 
conventions and style of the language and/or environment one is in. 
Otherwise, people who need to get involved in hacking the code, will usually 
feel frustrated as a result. We can look at the situation with ANSI C in 
which there's a zillion different styles present (e.g: GNU style, BSD style, 
Linux kernel style) as well as Hungarian Notation vs. traditional notation 
vs. Java notation. If you need a proof you can look at the complexity of GNU 
indent, or the length of Steve McConnell's "Code Complete" book. (or at least 
the relevant chapters of it). 

I know of a project (Subversion) in which there are several different styles 
followed throughout the code. I was actually corrected when a patch I made 
followed the main style instead of the component's specific style. 

With all due respect to TIMTOWDI, I'd rather not see Perl become so fragmented 
as far as style is concerned. The perlstyle document does not tell you what 
code to write (as is the case with Python's "There is one way of doing it") 
it just tells you how to format it. And I think that following these 
conventions can help more programmers feel at home with each other's code.

Sorry, but this triggered my opinion bit.

Regards,

	Shlomi Fish

> As far as I know there are more Windows uses than Linux users.
> More Christians than Jews.
> More cheap radios than state of the art sound systems.
>
> Back to the actual discussion. The conventions one uses have a lot to do
> with the programming culture one is accustomed to.

-- 

---------------------------------------------------------------------
Shlomi Fish      shlomif at iglu.org.il
Homepage:        http://shlomif.il.eu.org/

Quidquid latine dictum sit, altum viditur.
        [Whatever is said in Latin sounds profound.]




More information about the Perl mailing list