TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The Cost of Abstraction (2016)

72 pointsby wheresvic1about 6 years ago

13 comments

hu3about 6 years ago
I&#x27;ve seen excessive abstraction kill projects time and time again. The crime scene is similar in every case:<p>- What if we ever need to change database server or driver? Proceeds to write a layer to abstract data access<p>- We might have different login forms one day? LoginFormFactory it is<p>- This code hits our KV Redis&#x2F;memcache&#x2F;NoSQL by calling the driver lib directly? Can&#x27;t have that, I&#x27;ll write a CacheStorage or DocumentStorage layer.<p>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.<p>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&#x27;ll be sure to not make the same mistakes. This time, they&#x27;ll abstract even more so &quot;when one part of the project becomes bloated, it can be easily rewritten thanks to the abstractions&quot;. And the cycle continues.
评论 #19238622 未加载
评论 #19238250 未加载
评论 #19238257 未加载
评论 #19239167 未加载
评论 #19238792 未加载
评论 #19241110 未加载
评论 #19238963 未加载
pdpiabout 6 years ago
I find that there&#x27;s two core points that help me figure out where I&#x27;m missing some form of abstraction: the body of a function should only operate on a single level of abstraction, and it should only know technical details about one thing.<p>If you&#x27;re writing some database code, having high-level fetchMyEntity() calls mixed with connection&#x2F;resultset&#x2F;cursor logic is bad news.<p>If you&#x27;re writing something that reads from a message queue and stores the message in a database, the place where the two meet shouldn&#x27;t know much of anything about either the message queue or the database.<p>Obviously, exceptions exist where these rules need to be broken, but I find they&#x27;re fairly few and far between.
评论 #19238529 未加载
评论 #19238511 未加载
chestervonwinchabout 6 years ago
Lately I&#x27;ve been thinking about the similarities between the abstraction that results from post-hoc software refactoring and post-hoc mathematical proof &quot;refactoring&quot;. In both cases the refactoring is an attempt towards a more ideal form, but that form is almost always more impenetrable to newcomers.<p>E.g., a quote about the mathematician Carl Gauss:<p>&gt; Gauss&#x27; writing style was terse, polished, and devoid of motivation. Abel said, `He is like the fox, who effaces his tracks in the sand with his tail&#x27;. Gauss, in defense of his style, said, `no self-respecting architect leaves the scaffolding in place after completing the building&#x27;.
karmakazeabout 6 years ago
There&#x27;s a difference between deduplication&#x2F;extraction and abstraction which often seems to get lost. Abstraction is not about the mechanical reorganization of code. It is the structuring the code to follow a natural&#x2F;logical abstraction that exists outside of the code. The first clue is the name of the abstraction. If it describes how the &#x27;abstraction&#x27; works or what is going on inside it, then it&#x27;s best to leave it. An abstraction should be able to opaquely represent what it is. This is the <i>value</i> of abstractions, it let&#x27;s you not think about what&#x27;s inside while working at a higher level.<p>A similar issue I have is with people constantly &#x27;refactoring&#x27;. I choose to say I&#x27;m &#x27;factoring&#x27; code instead. If you can&#x27;t name the factors that you&#x27;re separating then it&#x27;s likely you&#x27;ll change your mind an end up &#x27;refactoring&#x27; it. Sometimes you take factored code and factor it further, which I don&#x27;t have a different name for, just more factoring.
sorokodabout 6 years ago
Introducing an abstraction is a way of extending the &quot;base&quot; language into the domain of the problem being solved. Viewed in this way, creating an inc_pair() function does not make sense beyond applications that deal with incrementing stuff. On the other hand, if we are moving a player on a grid, move_diagonaly_up() makes sense and is worth introducing into the extended language vocabulary.
thunderbongabout 6 years ago
Rule of Three<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Rule_of_three_(computer_programming)" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Rule_of_three_(computer_progra...</a>
danielovichdkabout 6 years ago
Abstractions are of course due when time is right.<p>It&#x27;s difficult to address but imo not be the goal from the get go, to introduce abstractions to a codebase.<p>There is also a cultural thing around abstractions where inexperienced developers look up to or are fascinated with the complexity of something or someone that brings that to the table.<p>It&#x27;s also a common feature of certain so called architects, because they probably feel they need to some advanced techniques.<p>The thing is though, that when you have worked with developers or architects that advocates for simple abstractions, and it over time proves that is both efficient and cheap, then you start to doubt complexity in total.<p>Also remember that complexity is often not complex per se, as long as you spend time on breaking that complexity down.<p>And then you have a better fundamental platform for solving what you need to.<p>Simple code is fast code. And also easier to change.
denart2203about 6 years ago
Very insightful. I like thinking about software complexity and one of the concerns there to deal with complex software is that the design and intentions should be communicated (which means either documentation or exist as a common understanding of purpose and function).<p>From your perspective, it means that there is also a need to establish agreements on the levels, depth and ways abstractions in the code are formed. Indeed, I worked with software where the functions and operations weren&#x27;t implemented in a messy way per sé, but the many levels of indirection, abstraction (and obscurement) made things just really difficult to read and a real tail-chaser when it came to maintenance.<p>Those levels can also make it much more difficult to understand the flow and the operations that are happening, because in many languages you pass references to data objects, so data gets changed in many ways.<p>Nice article, puts me into thinking mode again! :)
martin_drapeauabout 6 years ago
I totally agree that the cost of abstraction should become more important. It is often the number one cause of frustration when trying to add a new feature to an existing code base. Building a mental model of any code base takes time. Abstractions for the sake of abstraction makes it harder to grasp.
hyperpalliumabout 6 years ago
Abstraction should be based on whether the abstraction makes it easier or harder to reason about: to see, to predict consequences of decisions, to diagnose causes of behaviour.<p>Usually, the established abstractions of the domain are an excellent guide. Even if you think they are sub-optimal objectively, they are easier to reason about for experts in that field.<p>I like the article&#x27;s language of comtaining the &quot;damage&quot; code can do. A C-style modularizarion technique I haven&#x27;t seen used is long functions, with sections&#x27; variables&#x27; visibility limited by braces.
ameliusabout 6 years ago
That&#x27;s a really simply abstraction there, and I bet most people won&#x27;t even call that an abstraction.<p>It&#x27;s a bit like saying bricks are useless, by limiting the entire argument to a single brick.
评论 #19239034 未加载
评论 #19238247 未加载
nkingsyabout 6 years ago
These abstraction discussions seem to always result in commenters talking over each other. I would love to have these conversations rooted in a code sample. Otherwise no one is talking about the same thing.<p>If someone writes a blog series called “should this be abstracted, what’s the abstraction?” I think we would see some great discussion.
theaeolistabout 6 years ago
Structuring 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&#x2F;or information theory.
评论 #19238208 未加载
评论 #19238624 未加载