3 ms·
Does anyone read actually read code left-to-right, line-by-line? I for one start with the shape of the code -- the pattern of color (from syntax highlighting)
by ruricolist 11y ago
Does anyone read actually read code left-to-right, line-by-line?
I for one start with the shape of the code -- the pattern of color (from syntax highlighting) and negative space (from indentation) -- and only then focus on the different parts.
And Lisp is particularly helpful this way, because instead of paragraph-like blocks of code where you have to reconstruct the state of the code in your head by mentally modeling side effects, you can see the general outlines of what's happening from the levels of indentation.
I want to defend Lisp, of course, but I'm also genuinely curious about different ways people read code.
- hacker_9 11y agoI agree that the shape of the code is what I start with too: the syntax-highlighted keywords stick out as anchor points when scrolling, and I know from indentation where sections start and end. Example: if (...) { ... } else { ... } or loop { ... } After I home in on the words then yes I will generally read left to right, top to bottom. But another part of imperative style is code is usually split into separate paragraphs of related functionality - so I can usually jump down whole paragraphs too. The only other obvious variation I can think of is I will read bottom up when tracing the path a variable took to get to where I am currently looking.
- loqi 11y agoSame here. It's why I prefer to line-split conditionals in C-like languages like this: if (condition0 && condition1 && condition2) rather than the usual "trailing operator" style. You can immediately parse the left column as a sort of vertical operator that tells you how the individual conditions are being combined. But then, I also like Lisp. Prefix notation for "and" gives the same benefit directly, no tricky formatting required.