Context
Perhaps I'm just use to C-esque styled languages but having a sigil in front of a variable (e.g. $VAR
) always strikes me as weird.
Question
Why do some languages such as Perl and shell scripting have sigils in front of the variable names?
I can see it making sense for older languages like Basic (1960s) where the interpreter might not be smart enough to know what type of variable we are referring to. Looking at C in the 1970s, we see that is all but gone. In the 1980s, shell and Perl appeared and use the sigil notation yet Tcl, Erlang and others like C++ don't. In the 1990s, we see Python and Ruby not having sigils at all. Perhaps they do exist, but I haven't seen a recently developed programming language use sigils. I have, however, seen language do other stuff such as decorators from python @staticmethod
that can look like sigils but is used in a different context.
I don't code a lot in Perl but for bash, printf
is a function and wrapped in a command substitution, $(printf ...)
creates sprintf from C. With both of these options, I don't see gains of say using "This ${magic}String"
over printf "This %sString" "$magic"
especially when strings get really long. Similarly, ${#STR}
is confusing, especially to newer programmers that don't know what that piece of code does, whereas len str
is easier to read. Perhaps I'm just nitpicking over something that doesn't matter and everyone just accepts and moves on.
foobar
is a variable or the name of afile
, particularly in the case where both a variable and a file of that name exists?