Re:The Shapes of Code
by saltyfamiliar on Monday January 27, 2020 @11:33PM
(#22166483)
I'm glad I'm not the only one who pays attention to this. This is completely unsubstantiated and coming from a relatively inexperienced programmer, but it's been my experience that better code tends to produce nicer shapes. An obvious example not mentioned in the article arises when code is nested too deeply and too thinly, creating jarring and disproportionate peaks.
[ Parent
| on HN ]
Microsoft's docs have an interesting idea of what good nesting looks like:
https://docs.microsoft.com/en-us/previous-versions/windows/d...
Apparently 13 different indentation levels is good.
I actually find that surprisingly readable, probably because of the indent size which clearly allows the eye to see the blocks - and the size of my very large monitor - but this code seems to indicate a religious dogma about avoiding early returns, which would otherwise straighten it up.
Refactoring it effectively needs some sort of scope guard, too, to run `pfd->Release();` and the like. It's just as much dogma to write C++ like C, avoiding RAII.
Re:The Shapes of Code
by reilly3000 on Tuesday January 28, 2020 @02:43AM
(#22167260)
wow.
Re:The Shapes of Code
by DonHopkins on Tuesday January 28, 2020 @01:50AM
(#22167047)
Good code should be tightly wrapped around the problem, and reflect the shape of the problem itself.
But sometimes, the shape can be deceptive:
I review a lot of code for work and I agree with you that you can usually tell the quality of the code simply by looking at its outward appearance. Rough edges and bizarre shapes almost always indicate poor, unstructured thinking in the code itself.
Not saying I go by shape alone, but if it looks messy, that's a warning flag.