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 Law of Leaky Abstractions (2002)

110 pointsby skmabout 1 year ago

21 comments

cloogshicerabout 1 year ago
I&#x27;ve long been having a hunch that we&#x27;re currently in the &quot;wild west of abstraction&quot;.<p>I think we&#x27;re missing an essential constraint on the way we do abstraction.<p>My hunch is that this constraint should be that abstractions <i>must</i> be reversible.<p>Here&#x27;s an example: When you use a compiler, you can work at a higher layer of abstraction (the higher-level language). But, this means you&#x27;re now <i>locked into</i> that layer of abstraction. By that I mean, you can no longer work at the lower layer (assembly), even if you wanted to. You could in theory of course modify the compiler output after it&#x27;s been generated, but then you&#x27;d have to somehow manually keep that work in sync whenever you want to re-generate. Using an abstraction kinda locks you into that layer.<p>I see this problem appearing everywhere:<p>- Use framework &lt;--&gt; Write from scratch<p>- Use an ORM &lt;--&gt; Write raw SQL<p>- Garbage collection &lt;--&gt; Manual memory management<p>- Using a DSL &lt;--&gt; Writing raw language code<p>- Cross platform UI framework &lt;--&gt; Native UI code<p>- ...<p>I think we&#x27;re missing a fundamental primitive of abstraction that allows us to work on <i>each layer</i> of abstraction without being locked in.<p>If you have any thoughts at all on this, please share them here!
评论 #39622058 未加载
评论 #39622103 未加载
评论 #39621827 未加载
评论 #39623075 未加载
评论 #39621963 未加载
评论 #39623983 未加载
评论 #39623686 未加载
评论 #39633718 未加载
评论 #39621876 未加载
评论 #39621934 未加载
评论 #39622439 未加载
评论 #39634265 未加载
评论 #39628341 未加载
评论 #39624539 未加载
mjw1007about 1 year ago
I never liked the way he used TCP as an example here.<p>I don&#x27;t think it&#x27;s sensible to think of &quot;make it reliable&quot; as a process of abstraction or simplification (it&#x27;s obviously not possible to build a reliable connection on top of IP if by &quot;reliable&quot; you mean &quot;will never fail&quot;). &quot;You might have to cope with a TCP connection failing&quot; doesn&#x27;t seem to be the same sort of thing as his other examples of leaky abstractions.<p>TCP&#x27;s abstraction is more like &quot;I&#x27;ll either give you a reliable connection or a clean error&quot;. And that one certainly does leak. He could have talked about how the checksum might fail to be sufficient, or how sometimes you have to care about packet boundaries, or how sometimes it might run incredibly slowly without actually failing.
评论 #39621347 未加载
评论 #39621757 未加载
an1sotropyabout 1 year ago
I first learned about &quot;leaky abstractions&quot; from John Cook, who describes* IEEE 754 floats as a leaky abstraction of the reals. I think this is a good way of appreciating floating point for the large group of people who&#x27;s experience is somewhere between numerical computing experts (who look at every arithmetic operation through the lens of numerical precision) and total beginners (who haven&#x27;t yet recognized that there can&#x27;t be a one-to-one correspondence between a point on the real number line and a &quot;float&quot;).<p>* <a href="https:&#x2F;&#x2F;www.johndcook.com&#x2F;blog&#x2F;2009&#x2F;04&#x2F;06&#x2F;numbers-are-a-leaky-abstraction&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.johndcook.com&#x2F;blog&#x2F;2009&#x2F;04&#x2F;06&#x2F;numbers-are-a-leak...</a>
davesqueabout 1 year ago
I feel like this article should be called &quot;The Law of Bad Abstractions.&quot; I often see this cited as a blanket rejection of complexity in software. But complexity is unavoidable and even necessary. A skillful engineer will therefore design their abstractions carefully and correctly, balancing time spent thinking forward against time spent implementing a solution. I think Joel understands this, but it feels weird how he frames it as a &quot;law&quot;, as though it&#x27;s something he&#x27;s discovered instead of a simple fact that arises from the nature of what abstractions are: things that stand in for (or mediate interaction with) some other thing without actually being that thing. What a surprise that the stand-in ends up not being the actual thing it&#x27;s standing in for!
refactor_masterabout 1 year ago
A car is an implementation meant to deal with a problem (the weather), but never abstracts away physics or forces full buy-in to some alternate reality. You can’t just go around and say any imperfection in an implementation is a leaky abstraction. That’s not how it works.<p>My shoe is not abstracting away the terrain, nor is it leaky because it doesn’t handle <i>all</i> weather conditions. Well, it is leaky, but not in that sense.
评论 #39621996 未加载
BoiledCabbageabout 1 year ago
Young people should probably know that (as far as I recall) Joel more or less invented tech blogging as a form of advertising&#x2F;recruiting for your company.<p>Namely either listing out the process&#x2F;perks that a good engineering team should have and how conveniently his company has it. Or describing interesting and challenging problems they solved and how you can join them and solve problems like that too.<p>I don&#x27;t recall anyone popular doing it before him and it&#x27;s pretty much industry standard now. (Although, feel free to chime in if that&#x27;s wrong. But popular being a key word here),
评论 #39621571 未加载
wvenableabout 1 year ago
I loved this essay when it came out but I&#x27;ve come to dislike how &quot;leaky abstraction&quot; has become a form of low effort criticism that gets applied to almost anything.
simonwabout 1 year ago
I love this essay so much. I read it 22 years ago and it&#x27;s been stuck in my mind ever since: it taught me that any time you take on a new abstraction that you don&#x27;t understand, you&#x27;re effectively taking on mental debt that is likely to come due at some point in the future.<p>This has made me quite a bit more cautious about the abstractions I take on: I don&#x27;t have to understand them fully when I start using them, but I do need to feel moderately confident that I could understand them in depth if I needed to.<p>And now I&#x27;m working with LLMs, the most opaque abstraction of them all!
评论 #39621058 未加载
evanmoranabout 1 year ago
If you like this, my other favorite essay by Joel is Making Wrong Code Look Wrong:<p><a href="https:&#x2F;&#x2F;www.joelonsoftware.com&#x2F;2005&#x2F;05&#x2F;11&#x2F;making-wrong-code-look-wrong&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.joelonsoftware.com&#x2F;2005&#x2F;05&#x2F;11&#x2F;making-wrong-code-...</a>
评论 #39621083 未加载
lmmabout 1 year ago
This is wrong and even just looking at the examples is enough to understand that it&#x27;s wrong. Writing your program to use UDP instead of TCP won&#x27;t make it work any better when someone unplugs the network cable. An abstraction performing worse isn&#x27;t a &quot;leak&quot; - the abstraction is still doing what it said it would (e.g. the SQL query still returns the right results), and in practice very few query planners are worth tuning manually (indeed PostgreSQL doesn&#x27;t even offer you the ability to do hints etc., and that doesn&#x27;t seem to hurt its popularity). I&#x27;ve never understood why this post was so popular - it only ever seems to be used as an excuse for those who want to write bad code to do so.
评论 #39626558 未加载
xtiansimonabout 1 year ago
Are &quot;models&quot; and &quot;abstractions&quot; the same thing?<p>A recent post, `Mental Models: 349 Models Explained...` reminded me of the `Debits and Credits Model`, which works because of the Debit and Credits Formula or Accounting Equation (Assets = Equity + Liabilities). Minor leaks happening here and are usually stuffed into an account--so we don&#x27;t have to eat lunch at our desks.<p>The abstraction examples seem similar, but the discussion around leakage is interestingly different. For example @anonymous-panda suggests you sometimes want your abstraction to be leaky: _ &quot;...leaky abstraction would be when you need to still distinguish the error type and TCP wouldn’t let you...&quot;_
tgmaabout 1 year ago
Building White-Box Abstractions by Program Refinement[1]<p>[1]: <a href="https:&#x2F;&#x2F;people.inf.ethz.ch&#x2F;suz&#x2F;publications&#x2F;onward16.pdf" rel="nofollow">https:&#x2F;&#x2F;people.inf.ethz.ch&#x2F;suz&#x2F;publications&#x2F;onward16.pdf</a>
foobarianabout 1 year ago
&gt; But sometimes the abstraction leaks and causes horrible performance and you have to break out the query plan analyzer and study what it did wrong, and figure out how to make your query run faster<p>Hah. The more things change, the more they stay the same.
highfrequencyabout 1 year ago
&gt; “All abstractions leak, and the only way to deal with the leaks competently is to learn about how the abstractions work and what they are abstracting. So the abstractions save us time working, but they don’t save us time learning.”<p>Very nicely worded. But I would also add that:<p>1. An abstraction can often be manned by one person, so when it leaks only one person needs to understand it deeply enough to fix it.<p>2. The article seems to miss the <i>iterative</i> nature of abstractions. Over time, the goal is to iterate on the abstraction so that it exposes more of the stuff that matters, and less of the stuff that doesn’t matter. Perhaps all abstractions leak, but some leak way less often and save much more thinking in the meantime than others. Rather than lamenting the nature of abstractions we should focus effort on making them as practically useful as possible.
glialabout 1 year ago
This is well-written. I might suggest that what makes pure mathematics special is that abstractions in pure math are not leaky, unlike in (nearly?) every other domain.
评论 #39622197 未加载
titzerabout 1 year ago
Joel of course hits the nail on the head about the two major things that cause abstractions to fall apart: performance and bugs (or debugging). In programming languages we talk about abstractions all the time--PL of course is all about abstractions. A computational abstraction like a bytecode, source language, or even machine code, can be proven be a proper (or full) abstraction, meaning there is no way for implementation details to leak in--you cannot observe the electrons flowing by executing A+B, after all.<p>...until you start measuring sidechannels, or the CPU or compiler has a bug.<p>I think about this a lot when dealing with VMs; a complex VM cannot hide its complexity when programs care about execution time, or when the VM actually has a bug.
jacobmarbleabout 1 year ago
&gt; So the abstractions save us time working, but they don’t save us time learning.<p>I could say the same for programming with Copilot.
nextworddevabout 1 year ago
This is a long winded way to say that every abstraction has failure modes
评论 #39626620 未加载
Bostonianabout 1 year ago
Should have (2002) in title.
avgcorrectionabout 1 year ago
&gt; Back to TCP. Earlier for the sake of simplicity I told a little fib, and some of you have steam coming out of your ears by now because this fib is driving you crazy. I said that TCP guarantees that your message will arrive. It doesn’t, actually. If your pet snake has chewed through the network cable leading to your computer, and no IP packets can get through, then TCP can’t do anything about it and your message doesn’t arrive.<p>The argument is disqualified at this point. The whole world is a leaky abstraction because &lt;freak meteor hit could happen&gt;. At this point your concept is all-encompassing and in turn useless.<p>There are assumptions: this computation will finish eventually [assuming that no one unplugs the computer itself]. This does not make things leaky.<p>There are leaky abstractions I guess but not all are. A garbage collector that can cause memory errors would be leaky. I don’t know anything about garbage colletors but in my experience they don’t.<p>Then someone says that a garbage collector is leaky because of performance concerns (throughput or latency). That’s not a leak: that’s part of the <i>abstracting away</i> part—some concerns are <i>abstracted away</i>. To abstract away means to make it something that you can’t fudge or change. To say that “this is implementation-defined”. An abstract <i>list</i> is an abstraction in the sense that it has some behavior. And also in the sense that it doesn’t say <i>how</i> those behaviors are implemented. That’s both a freedom and a lurking problem (sometimes). Big reallocation because of amortized <i>push</i>? Well you abstracted that away so can you complain about it? Maybe your next step is to move beyond the abstraction and into the more concrete.<p>What are abstractions without something to abstract away? They are impossible. You have to have the freedom to leave some things blank.<p>So what Spolsky is effectively saying is that abstractions are abstractions. That looks more like a rhetorical device than a new argument. (Taxes are theft?)<p>EDIT: Flagged for an opinion? Very well.
评论 #39622461 未加载
评论 #39621091 未加载
评论 #39622382 未加载
评论 #39621504 未加载
评论 #39621437 未加载
评论 #39626647 未加载
评论 #39620771 未加载
williamcottonabout 1 year ago
Cannot everyone get the sense that how we currently build software is one gigantic leaky abstraction?
评论 #39621469 未加载
评论 #39621638 未加载
评论 #39621609 未加载