Some languages, such as BASIC (STRING$), Perl ($scalar, @array, %hash, &sub, *symbol), and others, use sigils affixed to variable names to indicate their types. Most other languages use either unadorned variable names or a single symbol to mark all variables.

(How) do programmers act differently in these languages than others? For example, do they make productive use of same-named variables of different types, does the ability to know the data type immediately on sight have a positive impact on code comprehension or debugging, does tracking multiple significant symbols introduce more opportunities for error instead? I'm looking to find what value, positive or negative, this design element brings to the user of the language (rather than the implementor).

For this question I'm thinking only of cases where this is enforced at the language level, not Hungarian notation or other naming conventions, and these are sigils for data type, not scope or lifetime.

  • 2
    $\begingroup$ Interesting question; the next time I run into one of the original implementors of Visual Basic I'll ask what motivated making those optional and whether there was any customer research behind it. $\endgroup$ Apr 12 at 0:45
  • $\begingroup$ Would Fortran count here? It doesn't (didn't?) use sigils, but would instead use the first letter of a variable name to determine its type, unless explicit specified, leading to the joke "God is real, unless declared integer". $\endgroup$ Apr 14 at 16:23
  • $\begingroup$ Fortran doesn't seem like it covers any of the relevant points except "know type on sight", but it doesn't even have that, as you note. Unless there is a version with sigils it doesn't seem like it can be hugely relevant, but perhaps there's something in it. $\endgroup$
    – Michael Homer
    Apr 14 at 21:46
  • $\begingroup$ I don't know if there are any "serious" languages with type sigils because you can only have as many types as you have sigils, which isn't a lot. I think Perl 4 (which I never used) had one type per sigil, but Perl 5 dumps [] lists and {} hashes and every custom type defined by every library into $, making the other Perl 4 types feel a bit vestigial. Also the sigils aren't really attached to the identifiers in Perl since $foo[...] indexes @foo, etc. $\endgroup$
    – benrg
    May 15 at 3:40
  • $\begingroup$ "Scalar" as a type encompasses quite a lot, but it's not less of a type for it. The indexing syntax of Perl 5 was a bit odd and Perl 6/now Raku use @foo and %foo when indexing as well, so it indicates the container type rather than the value type. I think both of those choices are defensible, although what I'd like is answers about what the effect of either of them is. $\endgroup$
    – Michael Homer
    May 15 at 3:56


You must log in to answer this question.

Browse other questions tagged .