119
Linear code is more readable (blog.separateconcerns.com)
you are viewing a single comment's thread
view the rest of the comments
[-] jadero@programming.dev 44 points 1 year ago

The left side (linear) looks like the code I write while I'm trying to figure out whether I understand the problem or I'm not quite sure what all I need to do prove that I can (or cannot!) solve the problem.

The code on the right, with all the "abstractions" looks like the code I end up with after I've got everything sorted out and want to make things easier to read, find, and maintain.

I actually find the code on the right easier to read. I treat it like a well written technical manual. For me, understanding starts with time spent on the table of contents just to get a sense of the domain. That is followed by reading the opening and closing sections of each chapter, and finally digging into the details. I stop at any level that meets my needs, including just picking and choosing based on the table of contents if there is no clear need to understand the entire domain in order to accomplish my goal.

I've preferred code written in that "abstracted" style since discovering the joy of GOSUB and JSR on my VIC-20.

[-] eager_eagle@lemmy.world 27 points 1 year ago

Exactly, the code on the right let us read only what matters when we're trying to solve a problem or understand it. The left one makes us read the whole thing and treats code like prose instead of reference material.

[-] tatterdemalion@programming.dev 3 points 1 year ago

And this is actually important when doing your job. I was reading code just yesterday written like the "left side" and it slowed me down because I was forced to understand everything that was happening in a big paragraph instead of just glossing over a function with an understandable name. These "inline functions" will often introduce temporary variables and stuff that forces the reader to understand the scope of things that really don't matter at the current level of abstraction.

this post was submitted on 15 Sep 2023
119 points (89.9% liked)

Programming

17314 readers
99 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS