DEV Community

Cover image for Choosing The Proper Level of Abstraction

Choosing The Proper Level of Abstraction

Lorenzo Pasqualis on December 05, 2017

This post was first published on CoderHood as Choosing The Proper Level of Abstraction. CoderHood is a blog dedicated to the human dimension of sof...
Collapse
 
xowap profile image
Rémy 🤖

Interesting. I'd add the notion of pain in the ass. Whenever I code something, I basically do the following:

  1. Write some code instinctively
  2. Test
  3. Fix bugs/add missing features
  4. GOTO 1 until working
  5. Figure out what's a pain in the ass and what works
  6. Now you clearly see your model and abstractions
  7. Delete everything and start over with a clear mind

(the more experienced you get the more you can do parts 1 to 4 in your head)

Then obviously, when some new feature comes in:

  1. Write it
  2. If you start feeling a pain in your ass, factorize whatever is required

The main idea here: factorize/automate when it hurts.

Collapse
 
tmfrisinger profile image
Travis Frisinger • Edited

I use TDD as a thinking tool in my development workflow. By doing this I can often avoid big up front design while driving towards the correct balance of abstraction. I always start by making it work, just puke the code in my brain on the screen, then make it pretty (reflect upon and refactor) my code to include any learning I may have discovered. I continue this process while pushing back against a tension of poor design / under abstraction until I can see concepts emerging.

I then collect these into methods and classes as I think about SOLID and Single Level of Abstraction during my reflect/refactor step of the TDD cycle.

This allows me to solve the problem at the micro-scale, thus rooting out the many assumptions I have when only solving in my mind or all at once. Our minds are horribly irrational and prone to biases, thus trying to problem solve at the macro-scale is an exercise in frustration and bugs.

By using TDD to slice the problem up, I am able to build context and grip the problem properly before I worry about the elegance of my solution.

Experience is a big factor in slicing the problem and applying TDD to guide my thinking. I like to remind myself TDD is any developer written test. Be it unit, integration, BDD, learning, etc. They all help guide and document my understanding of the problem at the various levels of complexity in the given domain.

Collapse
 
xowap profile image
Rémy 🤖

I never managed to do TDD. Even though I tried, it's just too hard for me.

I'm fine with testing but if you write your tests afterwards.

What I do however is, whenever I write an API (not a REST one), I start by writing on a paper how I want to use it. And then I figure out the internals.

Collapse
 
kspeakman profile image
Kasey Speakman

Excellent article as always. Totally resonates with my experiences and well explained.

Collapse
 
ben profile image
Ben Halpern

Truly wonderful read.

Collapse
 
lpasqualis profile image
Lorenzo Pasqualis

Thank you, Ben!!

Collapse
 
lpasqualis profile image
Lorenzo Pasqualis

For some reason, writing this post was like giving birth to a child (speaking as someone who never gave birth to a child). It took way too many hours. Maybe because of all the photoshopping of the images, or maybe is because it was hard to be happy with the definitions...

Collapse
 
rafalpienkowski profile image
Rafal Pienkowski

But the final result is excellent. Great article.

Collapse
 
lpasqualis profile image
Lorenzo Pasqualis

Thank you, Rafal!!

Collapse
 
dansilcox profile image
Dan Silcox

This is brilliant - and did make me chuckle as some of it is a little too familiar from some past projects!

Collapse
 
lpasqualis profile image
Lorenzo Pasqualis

Somebody built a super-computer when they were asked to build a pocket-calculator? :-) I know, it is a pretty familiar sight, isn't it?
Thank you for reading!!

Collapse
 
kprofic profile image
Krzysztof Profic

Fantastic reading.
And you made a right level of abstraction describing the problem as black ink splatter :)

Collapse
 
lpasqualis profile image
Lorenzo Pasqualis

Awesome! I was hoping someone would notice the meta-aspect of the analogy 😊