5 ms·
Does any other language require to use a special notation, similar to PHP’s “$”, any time a variable is referenced? I can only think of CSS, using “--“.
by lekevicius 5y ago
Does any other language require to use a special notation, similar to PHP’s “$”, any time a variable is referenced? I can only think of CSS, using “--“.
- krapp 5y agoPHP got that from Perl AFAIK. Bash does it too, and TCL.
- chubot 5y agoI'm pretty sure that historically shell is the common influence of PHP, Perl, and Tcl. PHP also inherits shell's here doc syntax, e.g. <<EOF . Not sure if Perl has that. Actually PHP started out as a bunch of cgi-bin scripts, if I recall. It was very much "a shell for the web". It kind of annoys me that they all require $ on the left, whereas shell only requires it on the right, which somehow makes more sense to me, e.g. a=$b # shell $a = $b # PHP and I think Perl
- pweezy 5y ago> It kind of annoys me that they all require $ on the left, whereas shell only requires it on the right Interesting - it makes it look like Bash uses $ to “read” from the variable, while in PHP/Perl $ only indicates that the rest of the symbol _is_ a variable.
- tyingq 5y ago>>PHP also inherits shell's here doc syntax, e.g. <<EOF . Not sure if Perl has that. It does. >>It kind of annoys me that they all require $ on the left Larry Wall says he went that direction to make namespace clashing between $dog, @dog, %dog, and "sub dog {}" (scalar, array, hashtable, function) a non-issue. http://www.wall.org/~larry/natural.html http://www.wall.org/~larry/natural.html ("Disambiguation")
- ZeroGravitas 5y agoRuby also has $ for global variables, which I assume it also got via Perl. And @ for instance variables, and @@ for class variables.
- TylerE 5y agoIt's much worse in perl, because it changes based on how you're using it. E.g. an array vs an element of an array.
- deleted 5y ago[deleted]
- ainar-g 5y agokrapp has already mentioned the Unix stuff. BASIC had a thing with a $ at the end of a string variable, iirc. Windows' CMD.EXE used %VAR% notation (and later !VAR! notation).
- toastal 5y agoThis is called a “sigil”
- todotask 5y agoIt's more than what most of us know, Rosetta Code is a good way to find. https://rosettacode.org/wiki/Variables https://rosettacode.org/wiki/Variables
- jansommer 5y agojsoniq uses the same notation https://www.jsoniq.org/ https://www.jsoniq.org/
- dylan604 5y agojquery, lodash, etc all added prefixes (or TIL: sigil) of somesort
- throw_m239339 5y ago> jquery, lodash, etc all added prefixes (or TIL: sigil) of somesort This is false they are not sigils at all. _ and $ are legal variable names in Javascript.
- nobleach 5y agojQuery's $ and lodash's _ are not prepended to a symbol to denote a variable. Both are objects actually. In the case of jQuery, $ === jQuery (the root jQuery object). The case that the parent is talking about is PHP's requirement that all variables are denoted as such `$variable_name`. (Perl and Bash also do this)
- dylan604 5y agoi forget that's what's actually being done under the hood.
- graftak 5y agoThat’s just (part of) the variable name and not really the same.
- tyingq 5y agoThese all use sigils on variables in one way or another: Unix Shells, AWK, Perl, Ruby, Tcl, Basic, PowerShell, DOS batch scripts
- icedchai 5y agoBasic uses them at the end for string variables... A$...
- Eric_WVGG 5y agoBack in the eighties, my father taught me that the “$” character in BASIC meant “string,” so when I later picked up PHP in ‘98 I mentally thought of $someVar as “string-someVar” (regardless of the actual type, which was of course no problem for PHP), kept that habit for well over a decade… I think it was partially my self-disgust over such silly and technically incorrect thinking that led me to bail for Node as soon that was a feasible alternative. The dollar sign does kinda look like a loose piece of shoestring, though
- agumonkey 5y agoI can't remember all details but in Lisp in small pieces, author describes variable handling with a table { creation, reference/access, modification, [deletion] } with each category had it's own optional syntax, many language will avoid this through context in which the symbol is, thus (+ a 1) equates (+ (deref a) 1), but he meant that it was a choice and not an obligation and some systems used $ or other syntactic constructs.
- deleted 5y ago[deleted]