What makes Lisp difficult to read?
The Lisp family of programming languages is known for its parenthesis-heavy syntax, which many find more difficult to read compared to languages like Python, Java, or C. Despite various attempts to improve its readability, Lisp's perceived lack of readability remains a consistent issue. Lisp developers often attribute this to familiarity, suggesting that once programmers get used to Lisp, the parentheses become less bothersome.
However, the author believes there is more to the story and proposes a deeper investigation into the cognitive science behind Lisp's syntax.
The primary difference between Lisp and more conventional languages is the placement of parentheses. In Lisp, every statement, expression, and function call uses the same syntax: (operation arguments...). This differs from C-style notation, which uses infix notation, keywords, and different types of delimiters. While the author acknowledges that these differences do have some impact on readability, they argue that their importance is overstated.
Instead, they focus on the placement of parentheses as the most prominent factor affecting Lisp's readability.
Human perception processes input differently depending on its characteristics. The Stroop effect demonstrates that certain types of input can hinder or aid visual processing tasks, acting as a form of "hardware acceleration" in our perception machinery. The author draws parallels between this concept and programming syntax, suggesting that designers should leverage these cognitive effects to create more readable interfaces.
Two visualizations demonstrate how the placement of parentheses can aid or hinder readability. The second visualization, which employs a "hardware acceleration" technique, allows readers to quickly identify outliers in the data. In contrast, the first visualization takes significantly longer to process, requiring an algorithmic time complexity of O(n), whereas the hardware-accelerated version achieves this in constant time, O(1).
The author connects this concept to programming syntax, using the Stroop and pop-out effects to illustrate how good designers can make interfaces more searchable using differently shaped icons, highlight colors, and other design principles. However, the cognitive science behind these effects is not always clear-cut and requires creative interpretation. The author acknowledges this limitation and emphasizes that readability is not entirely objective but rather influenced by subjective cognitive effects.
In the context of Lisp's syntax, the author focuses on the main goal of notation: to indicate how tokens should be grouped together. Gestalt Psychology offers several principles to explain how we perceive groupings. The law of proximity states that objects close to each other are perceived as related. C-style notation often adheres to this law due to the varied spacing created by parentheses and commas, which allows calls with multiple arguments to be perceived as a single visual entity.
In contrast, Lisp-style notation lacks such spacing, resulting in all function calls and arguments being perceived as separate entities.
The laws of closure and symmetry also play a role in Lisp's readability. The law of closure suggests that gaps between fragments can be mentally filled, forming a single entity. Parentheses naturally create visual groupings in Lisp, as they form an ellipse, making it easier for readers to perceive the grouping. The law of symmetry posits that symmetrical components are perceived as part of the same visual group, further aiding Lisp's readability.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.