The Cost of Abstraction (2016)
250bpm.com
The Cost of Abstraction (2016)
1–10 of 65 posts
Re: The Cost of Abstraction (2016)
#2Re: The Cost of Abstraction (2016)
#3It's a bit like saying bricks are useless, by limiting the entire argument to a single brick.
Re: The Cost of Abstraction (2016)
#4Structuring 1M line of code as one function or 1M functions is clearly equally absurd. What is the sweet spot? There must be an answer from psychology and/or information theory.
We're unlikely to encounter a problem that is solved with a single funtion, or as one function per line. But the important thing is to look at what the code should achieve. Most importantly, local decisions should be made based on what the code should achieve in a global context. Local syntactic optimizations are less important than the global picture.
I strongly agree with the Golang authors and with experienced C programmers that it's much better to write a few lines more and be more clear and explicit in exchange. Note that there are some additional lines that increase complexity, but I would argue that lines which contribute to clarity do not contribute complexity. In fact, those investments in additional lines usually decrease the number of moving parts.
Syntactic homogeneity is important so one can easily see what one piece of code achieves in the global context. It does not help if we micro-manage and constantly think about the type of for loop or lambda abstraction or error handling mechanism to use, only to shave another line off.
Unfortunately looking at the actual problem is what most people forget. Instead the discussion are about languages (filter, maaap. maaaaap), frameworks, libraries, object orientation without any concern of what these features can do towards reaching a specific goal.
Now that you mention information theory, I want to mention the term "Semantic compression", created by Casey Muratori. I think he has done at least one stream about it, which you should be able to find on YouTube. In general I recommend to follow him. He is one of the most experienced and no-nonsense guys I've found on the internet.
Re: The Cost of Abstraction (2016)
#5- What if we ever need to change database server or driver? Proceeds to write a layer to abstract data access
- We might have different login forms one day? LoginFormFactory it is
- This code hits our KV Redis/memcache/NoSQL by calling the driver lib directly? Can't have that, I'll write a CacheStorage or DocumentStorage layer.
Over time, this defensive mentality produces codebases that are so bloated that no one in the team can confortably grasp all the moving parts despite the project not being rocket science.
At that point, devs rather quit or get a substantial raise in order to continue working and ultimately endup leaving to start a new project. But this time, they'll be sure to not make the same mistakes. This time, they'll abstract even more so "when one part of the project becomes bloated, it can be easily rewritten thanks to the abstractions". And the cycle continues.
Re: The Cost of Abstraction (2016)
#6That's a really simply abstraction there, and I bet most people won't even call that an abstraction. It's a bit like saying bricks are useless, by limiting the entire argument to a single brick.
Re: The Cost of Abstraction (2016)
#7I've seen excessive abstraction kill projects time and time again. The crime scene is similar in every case: - What if we ever need to change database server or driver? Proceeds to write a layer to abstract data access - We might have different login forms one day? LoginFormFactory it is - This code hits our KV Redis/memcache/NoSQL by calling the driver lib directly? Can't have that, I'll write a CacheStorage or Docu…
For example, hiding POSIX-style select/poll vs Win32 Completion ports behind a common abstraction is something I tried recently, and seems to be HARD. Did not complete. Why? I started with the abstraction without being familiar with what the problem was. All that I knew was that I wanted to experiment with "game engine design".
Re: The Cost of Abstraction (2016)
#8I've seen excessive abstraction kill projects time and time again. The crime scene is similar in every case: - What if we ever need to change database server or driver? Proceeds to write a layer to abstract data access - We might have different login forms one day? LoginFormFactory it is - This code hits our KV Redis/memcache/NoSQL by calling the driver lib directly? Can't have that, I'll write a CacheStorage or Docu…
Agreed.
But none of your first few examples seem particularly egregious, if done well, they don't seem like they would sink a project.
I think part of the problem is developers underestimating just how hard it is to write an abstraction layer well. The juniors will say, "yeah I could do that in one sprint" then they start to build on top of it, the problems don't start to show until later, maybe when the dev who wrote it is gone.
I think the correct way to approach a problem like this is to acknowledge the cost of it up front. They are expensive. They don't just have to work. They have to work well and be readable.
Re: The Cost of Abstraction (2016)
#9If you're writing some database code, having high-level fetchMyEntity() calls mixed with connection/resultset/cursor logic is bad news.
If you're writing something that reads from a message queue and stores the message in a database, the place where the two meet shouldn't know much of anything about either the message queue or the database.
Obviously, exceptions exist where these rules need to be broken, but I find they're fairly few and far between.