Naming conventions: Difference between revisions

Added Perl verbiage
(Added Perl verbiage)
Line 893:
- Functions or methods that require reading another word end with ':'.
Examples: loop: , for: , new: , ...
 
=={{header|Perl}}==
This being Perl, you are of course give wide latitude in the names you can use for your program elements.
But it can be helpful to other programmers, and possibly your future self, to use letter case and underscores
to indicate the scope and nature of variable and routines, so their roles can be understood at a glance.
Some generally accepted conventions:
 
$ALL_CAPS_HERE constants
$Some_Caps_Here package-wide global/static
$no_caps_here function scope my/our/local variables
$_internal_use private
Note the use of underscores for readability.
Subroutines and variables meant to be treated as private can be prefixed with an underscore.
With all-caps constants, be careful for conflicts with Perl special variables.
Function and method names should be all lowercase.
 
Any reasonably modern version of Perl can use Unicode characters in names, so employ them where it makes sense. It
may be necessary to invoke the <code>use utf8</code> pragma that case.
 
<b>A caution about variables names and sigils</b>:
Perl won't stop you from giving three variables in the same scope the names
<code>%foo</code>, <code>@foo</code> and <code>$foo</code>, but that doesn't
mean it's a good idea. Here's a good example of [https://gist.github.com/SqrtNegInf/df5fbab044babc6ca16e229d2d1c669f what not to do] (offsite Perl code)
 
=={{header|Perl 6}}==
2,392

edits