code design

The essence of pretty code is that one can infer much about the code’s structure from a glance, without completely reading it. I call this “visual parsing”: discerning the flow and relative importance of code from its shape. Engineering such code requires a certain amount of artifice to transform otherwise working code into working, readable code, making the extra step to leave visual cues for the user, not the compiler. […]

- Code changes should blend in with the original style.

-Keep columns narrow. Just as with books and magazines, code should be narrow to focus the gaze.

-Break code into logical blocks within functions, and disentangle the purpose of separate blocks, so that each does a single thing or single kind of thing.

- Set off code blocks with whitespace and comments that describe each block.

- Reduce, reduce, reduce. Remove anything that will distract the reader.

- Two or more pieces of code that do the same or similar thing should be made to look the same. Nothing speeds the reader along better than seeing a pattern.

- The left edge of the code defines its structure, while the right side holds the detail. You must fight indentation to safeguard this property. Code which moves too quickly from left to right (and back again) mixes major control flow with minor detail.

This entry was posted in art & design, computing, Language and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>