Unicode Experiment
Hi all,
For a while I have being using symbols to show specific JavaScript functions and
operators[0], as a way to avoid making some mistakes that are (at least for me) really annoying.
Everything start because I was mixing asignment (=) with equality (==),
probably a common mistake. By chance I saw a video about APL[1][2], and after some research I thought that maybe my problem was a notation problem[3].
What I am doing
Assignment
Because JavaScript uses the same symbol for assignment and comparison[4],
whenever I saw an assignment I was reading “x equals …”. It was my mistake,
but the notation wasn’t helping.
So now I use the symbol `←` (U+2190 Leftwards Arrow) to indicate an assignment
Comparison
The customary recommendation is use strict equality (===),
but 3 symbols take too much space, so now I use the `≡` symbol (U+2261 Identical to)
switch and case
The switch statement looks like a list (to me), and I think is natural to use an arrow when enumerating, so I use the `🝘` (U+1F758 Alchemical symbol for pot ashes, the idea of this one come from the movie ‘bandersnatch’) and `➜` (U+279C Heavy round-typped rightwards arrow)
array push and pop
Push and pop, are somewhat difficult to parse, so I use `↧` (U+21A7 Downward Arrow from Bar) for push, and `↥` (U+21A5 Upwards Arrow from Bar) for pop.
array map
I alway use map, and `↦` (U+21A6 Rightwards Arrow from Bar ) is easier to spot than a word.
function
I think that `λ` (U+03BB Greek Small Letter Lamda ) is more easier to spot than the word function (and take less space)
return
My keyboard has the symbol `↲` (U+21B2 Downwards Arrow with Tip Leftwards) in the
return key, so it seems a good idea:
array filter and element
For array filter I use `σ’ (U+03C3 Greek Small Letter Sigma), and for element
`∈` (U+2208 Element Of)
-
With an arrow function is more easier to parse
The symbol for the arrow function is `⇒` (U+21D2 Rightwards Double Arrow)
A function example
An arrow function example
Conclusions
At least for me is easier to read symbols than words, I tried adding comments (function signatures) but is not the same (with symbols I can scan the code really fast).
The best part is, thanks to Emacs, this aesthetic change not have any effect in the source code(and I can turn on-off the changes fast).
Cheers and happy coding ![]()
Reference:
[0] https://www.emacswiki.org/emacs/PrettySymbol
displaying sequences of characters as fancy characters or symbols
[1]
[2] https://en.wikipedia.org/wiki/APL_(programming_language)
[3] Notation as a tool of thought
http://www.jsoftware.com/papers/tot.htm
By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and in effect increases the mental power of the race.
A.N. Whitehead
[4] assignment and comparison (JavaScript)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators
- Equality (==)
- Inequality (!=)
- Identity / strict equality (===)
- Non-identity / strict inequality (!==)
- Greater than or equal operator (>=)
- Less than or equal operator (<=)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators
