Skip Navigation

Linear code is more readable

blog.separateconcerns.com Linear code is more readable

Code linearity is more desireable than keeping abstraction layers separate.

46
Hacker News @lemmy.smeargle.fans bot @lemmy.smeargle.fans
BOT

Linear code is more readable

2 0

Linear code is more readable

5 2

You're viewing a single thread.

46 comments
  • The code on the right is better (though perhaps taken to an extreme) and what it comes down to is the code on the right makes you think in terms of the layers of the function when you make a change.

    Linear functions provide very little friction to changes that (when you see the interaction through all the layers) are actually quite bad. The code on the left will -- without extreme discipline -- become spaghetti as the years pass. Even with extreme discipline as the lines of code in the function grow, and other comments are added, the actual flow of the function will be harder to see and harder to grok because it can't all be put up on the screen at the same time.

    It's ultimately the same idea as minimizing side state/side effects. You want a bunch of small pieces that can be independently verified as doing their job, rather than one large thing that you can't understand at a glance.

46 comments