Search code examples
perlnaming-conventionstypeshungarian-notation

Is hungarian notation applicable to Perl?


In Perl, reference to anything is a simple scalar, and has the $ sigil. It's sometimes hard to say what kind of reference it is.

I personally prefix variable names for references with a letter, which indicates ref type. Examples:

my $aValues = [];                # arrayref
my $hValue  = {};                # hashref
my $oValue  = bless {};          # object
my $sValue  = \(my $s = 'foo');  # scalarref
...

I've seen both supporters and opponents to such notation. Do you use it? Does it have any disadvantages?


Solution

  • Personally I find hungarian notation hard to read. I just use English conventions:

    my $values; # is an array
    my $value;  # is a scalar
    my $value_hash; # is a hash
    

    I usually treat objects the same as scalars because how it's used makes it obvious enough that it is an object. However if I ever find a need to I'd use:

    my $value_obj;  # is an object