Leaky Abstractions Are Holding Us Back
Join the DZone community and get the full member experience.Join For Free
let’s just get right into it, shall we?
what is an abstraction?
before we can talk about leaky abstractions, and why they are bad, let’s define what exactly an abstraction is.
an abstraction is when we take a complicated thing and we make it simpler by generalizing it based on the way we are using or talking about that thing.
we do this all the time. our brains work by creating abstractions so that we can deal with vast amounts of information.
we don’t say “my dell inspiron 2676 with 2 gb of ram and a 512 gb hard drive, serial number 12398asd.” instead we say simply “my computer.”
in programming, abstractions let us think at higher levels. we create abstractions when we give a bunch of lines of code that get the username and password out of a textbox and log the user into our system, a name; login. and we use abstractions when we utilize apis or write to the “file system.”
without abstractions we’d have a really hard time managing the complexity of any software system. without abstractions, it would be pretty difficult to write any kind of non-trivial application.
if you want to feel what it is like to program with fewer abstractions, try serving up a web page with assembly code. if you want to feel what it is like to program with almost no abstractions, do the same exercise, but write your code in machine code… 0s and 1s.
how do abstractions “leak?”
abstractions leak when you have to understand the lower level concept to use the higher level concept.
this means the details of the lower level concept that are being abstracted away are leaking up through the higher level concept.
ever get a cryptic error message when an application you are using crashes? that is a leaky abstraction.
“memory location 00ffe133 could not be written to” is just bad news. it means that in order to understand what is going wrong with your application, you now have to understand the inner workings of the application. your abstraction has effectively “leaked.”
abstractions leak whenever you are forced to pull back the curtains and see the gnomes running in hamster wheels spinning the cogs.
why “leaking” is bad
i’m often surprised when i hear someone say “i like how you didn’t hide the details of what is really going on” about some code or some technology.
not being able to hide the details of what is really going on points to an inability to create the proper abstraction, which in my opinion, should be water tight.
it is not a good thing that we can see what is really going on. no, it is actually a very bad thing, because it forces us to think at the higher level some of the time, but have to switch gears to drop down to the lower level some of the time.
leaky abstractions prevent us from being able to comfortably drive the kids to school; we have to constantly keep looking in our rear view mirror and checking to see if those rowdy kids who insist on sitting at the back of the bus are causing trouble again.
a good abstraction hides the details so well that we don’t ever have to think about them. a good abstraction is like a sturdy step on a ladder, it allows us to build another step above us and climb up it. a leaky abstraction is like a wobbly rotted wood rung; put too much weight on it and you’ll fall through—it traps you at the current step—you can’t go any higher.
shouldn’t we understand how things really work?
no! stop already! enough with the guilt trips and unnecessary burdens. you are defeating the purpose of abstractions and stunting further growth.
you only “need” to know the details if you want or need to know the details.
i know that many people want to know how things really work, myself included for many things, but in many cases i don’t need to understand how things really work.
for example, i can buy and use a watch without understanding how the watch works. it really is better that way. i don’t need those details floating around in my head. i get no benefit from knowing what is going on inside my watch and frankly, i don’t want to know.
personally, i have a similar view on cars, although i know that many other people don’t, so that is why i didn’t use it as my first example.
when i buy a car, i just want to drive it. i don’t want to remember when to rotate tires, check fluids, etc. waste of my time. i don’t want to know how the engine works or anything about it besides i have to put gas in, turn a key, and press a few pedals to make the thing go. i know i could save money servicing my own car, but you know what? i’d rather pay money than have to do it myself. and since that is the case, as long as i can find someone i trust to work on my car, i don’t want that abstraction to leak.
the same with machine code and compilers. yes, it is interesting to understand how memory mapping and cpus and logic gates work and how my c# code gets compiled into msil which is interpreted by the clr and so forth and so on, until it ends up as electrons operating on registers in my cpu. and i learned about how much of that works, because i was interested, but let’s be completely honest here. that abstraction is really good. it is so good and so air-tight, that i don’t need to know all of that crap in order to write a web app. if i did, i’d probably find another profession, because my brain would explode every time i tried to write the simplest piece of code.
by the way, if you do want to understand what is happening behind many of those abstractions, i highly recommend charles petzold’s book: “code: the hidden language of computer hardware and software”. (this is the kind of book you read for “fun,” not because you need to know this information.)
leaking abstractions in technology
too many technologies and frameworks today are leaky, and this is bad– really bad.
want an example? whatever happened to orm (object relational mapping?)
nothing. nothing happened. it was invented, oh, like thousands of years ago and while lots of other technologies and frameworks grew up and got jobs and left the nest, orm is still a fat unemployed balding 30 year old man playing wow all day in his mum and dad’s basement.
don’t get me wrong. i use orms; i sometimes like to think i like orms. but, i can’t use them well because i have to understand sql and what is going on in my relational databases anyway. what good is that?!
seriously. this is a completely failed abstraction. the leakiness of it makes it actually more work to learn an orm framework, because in learning one you must also learn hairy details of sql and understand what n+1 means and so on. you can’t just fire up your orm and put in the konami code, you have to blow the cartridge out and fiddle with the reset button half a dozen times. useless.
i could go on and on with examples of leaky abstractions in technology and how they are holding us back, but i think you get the point by now.
leaky abstractions are bad. they don’t do anything good for us besides require us to know more and add more points where things can go wrong. we’ve got to seal up these abstractions, if we want to be able to keep climbing the software development ladder. you can’t keep building a tower if you have to worry about every single block beneath you. you eventually get to a point where you can’t keep it all straight and your tower comes crashing to the floor.
leaky abstractions and you
so, what can you do about it?
you really have to make a choice. am i going to hide the details so that no one needs to know about them, or am i going to expose the whole thing? either make a really good abstraction that doesn’t require someone using your code to understand what is going on underneath that abstraction or don’t attempt to make an abstraction at all.
it takes more effort to create good abstractions. sometimes the effort required is orders of magnitude greater. but, if other people are going to use your abstraction, to save the mental burden of understanding what is happening beneath it is going to go a long way in making up for your extra effort.
10 steps to learn anything quickly course
by the way, i just released by 100% 10 steps to learn anything course . if you want free access to it, just signup to my newsletter here . it is a totally free video course and optional workbook that reveals the process i use to quickly learn technologies.
the post leaky abstractions are holding us back appeared first on simple programmer .
Published at DZone with permission of John Sonmez. See the original article here.
Opinions expressed by DZone contributors are their own.
Performance Comparison — Thread Pool vs. Virtual Threads (Project Loom) In Spring Boot Applications
Integrate Cucumber in Playwright With Java
Adding Mermaid Diagrams to Markdown Documents
Operator Overloading in Java