Sigils - the characters on the start of variable names in Perl, Ruby and Fortran
Archive - Originally posted on "The Horse's Mouth" - 2011-09-10 18:21:39 - Graham Ellis
A sigil (from Latin sigillum "seal") is a symbol created for a specific magical purpose. A sigil is usually made up of a complex combination of several specific symbols or geometric figures, each with a specific meaning or intent. In computer programming, a sigil is a special symbol attached to a variable name, showing the variable's datatype or scope. Philip Gwyn, in 1999 adopted the term "to mean the funny character at the front of a Perl variable" and the term is applicable to Ruby too.
Ruby - everything is an object, the sigil defines the scope;
@abc Object variable. There's an @abc within each object in a class $abc Global variable. Shared between methods / functions without being passed @@abc Class variable. There's only one @@abc in a class, shared between all objects in the class abc Local variable within current function / method / other similar closure Abc Constant. Once set, it's read only :abc Not really a variable either. An efficient unchanging piece of text.
Perl - definition is data type. Scope controlled with presence (or absence) of keywords my or our
$abc Scalar. Integer, float, string, reference or regular expression @abc A list of scalars. Members are numbered upward from 0, so an ordered collection %abc A hash of scalars. Members are keyed by any scalar, often a string. An unordered collection abc A file handle &abc A piece of code. A sub *abc A Typeglob - a joint name for one of each of the abpve.
Rather than special characters, Fortran used specific start letters for its variable names to represent interegers (start letter I J K L M and N) and reals (A to H and O to Z). An IMPLICIT statement was added at Fortran 77
Hungarian notation is where a variable name starts with a group of letters which are mnemonics for the type or purpose of that variable. That's followed by whatever name the programmer has chosen. So Fortran is an example where Hungarian notation is built into the language.
Hungarian notation is also often used as a convention (rather than a rule) in languages such as C and C++. It helps the coder who's revisiting the program for maintainance purposes to see what's what at a later date without having to scroll all the way back to the top of a piece of code. [example]: int weight = 96;
int *pWeight = &weight;
int &rWeight = weight;