One of the weird historical accidents of programming languages is that
so many of them use $
for important things. The reason is just that
out of the available punctuation, nearly all of it has a mathmatical or
other predefined use that makes sense to retain in a programming
language context, while $
(and also @
and #
) do not.
Still, $
annoys me, it's so asymetric that we use it all
over our code, and never a £
or ฿
to be seen.
The one language that manages to use $
nicely, IMHO, is Haskell.
Recently I noticed that it has an actual visual mnemonic in its use of $
.
And it's used for something I've not seen in other languages.
The visual mnemonic of $
is that it looks like an opening
parenthesis, with the related closing parenthesis on a line below it.
(something (that
(lisp folks
(are (very (familiar with)))
)
))
And this is also the problem that $
solves:
something $ that $
haskell folks $
are $ very $ familiar with
This is a trivial feature.. but oh so useful.
The implementation in Haskell of $
is simply:
f $ x = f x
infixr 0 $
Just function application, but at a different precedence than usual.
I am now very addicted to my $
. Out of 15 thousand lines of code,
only 87 contain ))
, while 10% use $
.
In BASIC, $ is mnemonic for STRING ($TRING).
To someone who started to learned BASIC as first programming language at age six, and English as second natural foreign language at age twelve, it’s natural. My father had to explain me that it also means “Dollar” and is the USA currency…
I think % is because you can do Modulo with integers but not with reals ☺