You're right, narrow columns improve readability. However, I believe the question we should consider is "is 'readability' in a newspaper and 'readability' in code defined in the same way?".
I think the answer is negative. For example, typefaces with serifs, ligatures and variable widths improve readability, but when it comes to programming - we prefer monospace fonts. Do newspapers come with "dark mode"? :-) Perhaps there are other differences too.
Code is not always read like prose. One could argue that the programmer operates in several modes, each at different levels of abstraction:
- (a) high-level: "iterate over a list"
- (b) low-level: "this is a for loop that begins at 0 and ends at X, and increments the counter with 1 at each step"
(b) is necessary when you're debugging it, but once the code was written and tested, subsequent reads of it can go at level (a).
For example, this Python chunk would be autoformatted by black ("the uncompromising code formatter"); note that you might have to zoom out a bit to make sure Slashdot doesn't add its own line breaks:
for route_id, route_number, name in curs:
result[route_id] = Route(route_id, route_number, name)
result[route_id].stations = self.load_route_stations(route_id)
result[route_id].station_ids = [station.station_id for station in result[route_id].stations]
result[route_id].checkpoints = self.load_route_checkpoints(route_id)
result[route_id].checkpoint_ids = [entry.checkpoint_id for entry in result[route_id].checkpoints]
to:
for route_id, route_number, name in curs:
result[route_id] = Route(route_id, route_number, name)
result[route_id].stations = self.load_route_stations(route_id)
result[route_id].station_ids = [
station.station_id for station in result[route_id].stations
]
result[route_id].checkpoints = self.load_route_checkpoints(route_id)
result[route_id].checkpoint_ids = [
entry.checkpoint_id for entry in result[route_id].checkpoints
]
In the top code excerpt, the programmer sees it as "each line sets an attribute of the object in question", mode (a). Whereas in the bottom excerpt some of these logical operations span across multiple lines and you're forced into mode (b), because you're not sure if these several lines are a part of the same logical operation or not, until you read them.
This reminds me of the "Thinking fast and slow" dichotomy, where "system 1" makes a fast decision, while "system 2" makes a slow one. In my experience, quite often when long lines are broken down into multiple lines I am forced to deal with them using "system 2" when "system 1" would suffice.
So, there are cases when long lines are appropriate.