Step 13: Code Layout Matters ~ Steve Freeman

Birat Rai
2 min readOct 7, 2017

--

This is the Thirteenth Step towards gaining the Programming Enlightenment series. If you didn’t learn the Twelfth Step, read it.

“It’s Harder to Read Code than to Write it” ~Joel Spolsky

Reading Code is what programmers do all the time. If it’s harder to read code, than development time will be spent just to understand the code.

A beautifully laid out code means we can see structures of code which gives up certain shape in our mind and gives us understanding where to navigate to find our certain piece of code and make change.

“Indeed, the ratio of time spent reading versus writing is well over 10 to 1. We are constantly reading old code as part of the effort to write new code. …[Therefore,] making it easy to read makes it easier to write.”

Robert C. Martin

Why we want to make the layout beautiful?

It turns out that style matters in programming for the same reason that it matters in writing. It makes for better reading. ~ Douglas Crockford

As you can see almost 70% of time is spent on understanding code, it gives us a sense why Code Layout matters and why we should write a clean code. Even we can argue a beautiful Code Layout is the outcome of a beautiful Code Architecture aka some patterns (MVP, MVC, MVVM ..)

  • Easy to scan. First impression is the last impression, if the code gives a visual pattern, every where in the project, we can have a styling confidence where is the particular piece of code is.
  • Expressive Layout. More powerful IDE’s have surfaced which have a automatic formatter which one can set according to the Coding standard which the team follows.
  • Compact Format. It’s been talked about having a character limit per line, so that it’s easier to scan. Giving a class Single Responsibility will also make that class compact and easier to understand what it actually does.

TL;DR We don’t have to spend much time making layout beautiful, explore the powerful IDE and use auto-formatter.

--

--

Birat Rai
Birat Rai

Responses (1)