Sigil (computer programming)

In computer programming, a sigil () is a symbol affixed to a variable name, showing the variable's datatype or scope, usually a prefix, as in codice_1, where codice_2 is the sigil.
"Sigil", from the Latin "sigillum", meaning a "little sign", means "a sign or image supposedly having magical power". Sigils can be used to separate and demarcate namespaces that possess different properties or behaviors.
Historical context.
The use of sigils was popularized by the BASIC programming language. The best known example of a sigil in BASIC is the dollar sign ("codice_2") appended to the names of all strings. Many BASIC dialects use other sigils (like "codice_4") to denote integers and floating point numbers and their precision, and sometimes other types as well.
Larry Wall adopted shell scripting's use of sigils for his Perl programming language. In Perl, the sigils do not specify fine-grained data-types like strings and integers, but the more general categories of scalars (using a prefixed "codice_2"), arrays (using "codice_6"), hashes (using "codice_4"), and subroutines (using "codice_8"). Raku also uses secondary sigils, or twigils, to indicate the scope of variables. Prominent examples of twigils in Raku include "codice_9", used with self-declared formal parameters ("placeholder variables"), and "codice_10", used with object attribute accessors (i.e., instance variables).
In CLIPS, scalar variables are prefixed with a "codice_11" sigil while multifield (e.g., a 1-level list) variables are prefixed with "codice_12".
In Common Lisp, special variables (with dynamic scope) are typically surrounded with codice_13 in what is dubbed the "earmuff convention". While this is only convention, and not enforced, the language itself adopts the practice (e.g., *standard-output*). Similarly, some programmers surround constants with codice_14.
In CycL, variables are prefixed with a "codice_11" sigil. Similarly, constant names are prefixed with "codice_16" (pronounced "hash-dollar").
In Elixir, string sigils are provided via the "codice_17" symbol.
In MAPPER (aka BIS), named variables are prefixed with "<" and suffixed with ">" because strings or character values do not require quotes.
In mIRC script, identifiers have a "codice_2" sigil, while all variables have a "codice_4" prefixed (regardless of local or global variables or data type). Binary variables are prefixed by an "codice_8".
In the MUMPS programming language, "codice_2" precedes intrinsic function names and 'special variable names' (built-in variables for accessing the execution state). "codice_22" precedes non-standard intrinsic function names. "codice_23" precedes extrinsic function names. Routines (used for procedures, subroutines, functions) and global variables (database storage) are prefixed by a caret (^). The last global variable subtree may be referenced indirectly by a caret and the last subscript; this is referred to as a "naked reference". System-wide routines and global variables (stored in certain shared database(s)) are prefixed with ^%; these are referred to as "percent routines" and "percent globals".
In Objective-C, string literals preceded with "codice_6" are instances of the object type codice_25 or, since clang v3.1 / LLVM v4.0, codice_26, codice_27 or codice_28. The prefix-codice_6 is also used on the keywords codice_30, codice_31, and codice_32 to express the structure of class definitions. Within class declarations and definitions as well, a prefix of codice_33 is used to indicate member methods and variables, while prefix codice_14 indicates class elements.
In the PHP language, which was largely inspired by Perl, "codice_2" precedes any variable name. Names not prefixed by this are considered constants, functions or class names (or interface or trait names, which share the same namespace as classes).
PILOT uses "codice_2" for buffers (string variables), "codice_37" for integer variables, and "codice_13" for program labels.
Python uses a "codice_6" prefix, called "pie syntax", for application of decorators and a "codice_40" prefix, called "dunder", for "private" attributes.
In Ruby, ordinary variables lack sigils, but "codice_2" is prefixed to global variables, "codice_6" is prefixed to instance variables, and "codice_43" is prefixed to class variables. Ruby also uses (strictly conventional) suffix sigils: "codice_11" indicates a predicate method returning (usually) a boolean value; and "codice_45" indicates that the method may have a potentially unexpected effect, and needs to be handled with care.
In Scheme, by convention, the names of procedures that always return a boolean value usually end in "codice_11". Likewise, the names of procedures that store values into parts of previously allocated Scheme objects (such as pairs, vectors, or strings) usually end in "codice_45".
Standard ML uses the prefix sigil "codice_48" on a variable that refers to a type. If the sigil is doubled, it refers to a type for which equality is defined. The "codice_48" character may also appear within or at the end of a variable, in which case it has no special meaning.
In Transact-SQL, "codice_6" precedes a local variable or parameter name. System variables (known as global variables) are distinguished by a "codice_43" prefix.
In Windows PowerShell, which was partly inspired by Unix shells and Perl, variable names are prefixed by the "codice_2" sigil.
In XSLT, variables and parameters have a leading "codice_2" sigil on use, although when defined in codice_54 or codice_55 with the "codice_56" attribute, the sigil is not included. Related to XSLT, XQuery uses the "codice_2" sigil form both in definition and in use.
In MEL, variable names are prefixed by "codice_2" to distinguish them from functions, commands, and other identifiers.
Similar phenomena.
Shell scripting variables.
In Unix shell scripting and in utilities such as Makefiles, the "codice_2" is a unary operator that translates the name of a variable into its contents. While this may seem similar to a sigil, it is properly a unary operator for lexical indirection, similar to the codice_13 dereference operator for pointers in C, as noticeable from the fact that the dollar sign is omitted when assigning to a variable.
Identifier conventions.
In Fortran, sigils are not used, but all variables starting with the letters I, J, K, L, M and N are integers by default. Fortran documentation refers to this as "implicit typing", though explicit typing is always available to allow any variable to be declared with any type. (The choice of range I–N conforms to traditional mathematical naming conventions.)
Various programming languages including Prolog, Haskell, Ruby and Go treat identifiers beginning with a capital letter differently from identifiers beginning with a small letter, a practice related to the use of sigils.
Stropping.
Actually a form of stropping, the use of many languages in Microsoft's .NET Common Language Infrastructure (CLI) requires a way to use variables in a different language that may be keywords in a calling language. This is sometimes done by prefixes. In C#, any variable names may be prefixed with "codice_6". This is mainly used to allow the use of variable names that would otherwise conflict with keywords. The same is achieved in VB.Net by enclosing the name in square brackets, as in codice_62.
The "codice_6" prefix can also be applied to string literals; see literal affixes below.
Hungarian notation.
Related to sigils is Hungarian notation, a naming convention for variables that specifies variable type by attaching certain alphabetic prefixes to the variable name. Unlike sigils, however, Hungarian notation provides no information to the compiler; as such, explicit types must be redundantly specified for the variables (unless using a language with type inference). As most standard compilers do not enforce use of the prefixes, this permits omission and also makes code prone to confusion due to accidental erroneous use.
Literal affixes.
While sigils are applied to names (identifiers), similar prefixes and suffixes can be applied to literals, notably integer literals and string literals, specifying either how the literal should be evaluated, or what data type it is. For example, codice_64 evaluates to the value 16 as an unsigned long long integer in C++: the codice_65 prefix indicates hexadecimal, while the suffix codice_66 indicates unsigned long long. Similarly, prefixes are often used to indicate a raw string, such as codice_67 in Python, which represents the string with value codice_68; as an escaped string this would be written as codice_69.
As this affects the semantics (value) of a literal, rather than the syntax or semantics of an identifier (name), this is neither stropping (identifier syntax) nor a sigil (identifier semantics), but it is syntactically similar.
Java annotations.
Compare Java annotations such as @Override and @Deprecated.
Confusion.
In some cases the same syntax can be used for distinct purposes, which can cause confusion. For example, in C#, the "codice_6" prefix can be used either for stropping (to allow reserved words to be used as identifiers), or as a prefix to a literal (to indicate a raw string); in this case neither use is a sigil, as it affects the syntax of identifiers or the semantics of literals, not the semantics of identifiers.