Whitespace - still underrated
I feel like whitespace and its benefits are still not fully recognized in the community. There are still horrible examples of missing whitespace as well as many missed opportunities.
The core guidelines still state "NL.15: Use spaces sparingly" and "Reason: Too much space makes the text larger and distracts."
What does "make the text larger" even mean? Are they really concerned that the code will take too long to compile (as was one of my former employers) Then they present a single stupid example where someone wrote #include < map > and char * argv which obviously look like a comparison and multiplication. No hints as to where whitespace is good or recommended.
My main point is that the correct use of whitespace frees up mental capacity for more important stuff. Processing a line of code (or other information) might take you half a second less if it is well formatted. These numbers obviously add up over a day where you go over thousands of lines. Badly formatted lines constantly have you scan for clues as to where things begin and end.
There is always an element of personal preference, but that does not mean there are not best practices. Joe might still prefer short cryptic names, yet it is strongly discouraged today.
Some Examples:
-
Imho, the single most important guideline would be: Round and curly brackets, commas, operators, assignments and comparisons always have a single space. This is just how most brains work. We recognize entities easier when they are separated. There is a reason that commas and periods in standard text have a space.
-
There is an element of personal preference, but
-
Having blank lines between separate logical blocks in a function is not for presentation purposes only. It is essential for readability.
-
I recently found out that the main reason I can't read templated error messages well is NOT that they are too complicated. It is simply that they are missing whitespace! You have to scan them 'char by char' to find the next closing '>' or ')'
-
I'm using a logging lib, and it prints
[2023.02.28-23.44.16:187]as the timestamp. How can you ever do that? It's just impossible see at a glance when this was logged. Just print[2023-02-28] [23:44:16.187]
TLDR: maybe just make this a poll or feeler episode of how many whitespace dinosaurs are out there.