Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Formatting variable names

by hippo (Bishop)
on Nov 29, 2020 at 11:38 UTC ( [id://11124355]=note: print w/replies, xml ) Need Help??


in reply to Formatting variables

all lower case with an underscore sometimes between words

This is called snake case.

capitalising the first letter of each word other than the first

This is called camel case.

I'm wondering how you do it, why you do it that way and if you think it matter a great deal.

I use snake case because it is more legible to me. It doesn't matter overly so long as you are consistent within any one body of code.


🦛

Replies are listed 'Best First'.
Re^2: Formatting variable names
by stevieb (Canon) on Nov 29, 2020 at 15:32 UTC
    "I use snake case because it is more legible to me."

    Note that snake case has always been the de-facto, unofficial standard for Perl code since forever. I develop in numerous languages, and typically stick with what the language norm is. That way, others who read, use or work on my code will be familiar with whatever language the code is written in. If they add to my code, they'll typically write using the language 'standard', and I'm far less likely to get variations.

    There's not much worse than having a source file with functions or variables where some are like_this and others are likeThis or even LikeThis. Inconsistency makes code harder to read, and harder to understand when looking at it from a distance.

    In Perl, AllUpperCamelCase represents a package name. snake_case represents variables, functions and methods. ALL_UPPER_SNAKE or ALLUPPER is often used for env vars and constants.

Re^2: Formatting variable names
by Bod (Parson) on Nov 29, 2020 at 13:32 UTC

    This is called snake case.
    This is called camel case.

    It hadn't occurred to me that they might have names!

      These two are joined by several others in having colloquial names:

      Naming convention, multiple-word identifiers

      I've seen kebab-case used in Scheme. It is also convenient in domain names, though there are some sound arguments in favor of registering both the hyphenated and non-hyphenated version of a given domain. One reason is that it's hard, in an audio advertisement, to specify the hyphen without making that the most memorable part of the domain.


      Dave

        Thanks - I was going to ask if there are others...

        though there are some sound arguments in favor of registering both the hyphenated and non-hyphenated version of a given domain

        I certainly try to register hyphenated and non-hyphenated variations of domains names as well as different TLDs depending on the importance of the project. I've been bitten a few times with missing out on a domain!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-16 03:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found