seven pillars of pretty code christopher seiwald
play

Seven Pillars of Pretty Code Christopher Seiwald (Presented by - PowerPoint PPT Presentation

Seven Pillars of Pretty Code Christopher Seiwald (Presented by Ulrik Schou) Overview/motivation Visual parsing Working code -> working readable code. 1,2,3,4,5: Formularic 6,7: requires intuition Pillar 1 : Blend in. -


  1. Seven Pillars of Pretty Code Christopher Seiwald (Presented by Ulrik Schou)

  2. Overview/motivation ● Visual parsing ● Working code -> working readable code. ● 1,2,3,4,5: Formularic ● 6,7: requires intuition

  3. Pillar 1 : Blend in. - Changes should be invisible. - scope: absolutely within functions, generally within a file, and if you're lucky across the system. - if too ugly code : rewrite

  4. Pillar 2: Bookish - Keep columns narrow: like a book - Remedies : shorter names lineup function arguments streamline logic - Rule of thumb: 80 cols.

  5. Pillar 3: Disentangle Code Blocks Break code into blocks within functions. Each block should do a ”single kind of thing”. Approaches: minifunctions = blocks. When no minifunctions: organize activity(init vars, param check, computing results, returning results, printing debug). Apply approaches recursively.

  6. Pillar 4: Comments Set off code blocks with whitespace and comments that describe each block. Comments should rephrase not be a translation. Big comments for subtle or problematic code. 15% blank and 25% comment lines.

  7. Pillar 5: Declutter Reduce, reduce, reduce. Remove anything that will distract the reader. Tighter scope = shorter names. Avoid: unnessesary complicated statements needless casts heavy parenthesizing. Drop all dead code.

  8. Pillar 6: Make Alike Look Alike Two or more pieces of code that do the same or similar thing should be made to look the same(patterns). Line up Look Alikes. Initialize variables together. Consistently use 'this' (or don't). Line up function arguments. Consistently use {} around if/else clauses: either all blocks have them, or none do. Put the { of a if/for/while on its line (because the closing } is). Break apart conditionals at the &&'s or ||'s and align them.

  9. Pillar 7: Overcome indentaion. The left edge of the code defines its structure, while the right side holds the detail. -> Fight indentation. Approaches: one level of indentation for if/while/for/do/switch. Use break/continue/return even goto Rearrange conditionals..

  10. Overview ● Blend In ● Bookish ● Disentangle Code Blocks ● Comments ● Declutter ● Make Alike Look Alike ● Overcome Indentation

  11. The end Any questions?

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend