In
software development
Software development is the process of conceiving, specifying, designing, programming, documenting, testing, and bug fixing involved in creating and maintaining applications, frameworks, or other software components. Software development invol ...
, a leaky abstraction is an
abstraction
Abstraction in its main sense is a conceptual process wherein general rules and concepts are derived from the usage and classification of specific examples, literal ("real" or "concrete") signifiers, first principles, or other methods.
"An abstr ...
that leaks details that it is supposed to abstract away.
As coined by
Joel Spolsky
Avram Joel Spolsky (born 1965) is a software engineer and writer. He is the author of ''Joel on Software'', a blog on software development, and the creator of the project management software Trello. He was a Program Manager on the Microsoft Exce ...
, the Law of Leaky Abstractions states:
This statement highlights a particularly problematic cause of software defects: the reliance of the software developer on an abstraction's infallibility.
Spolsky's article gives examples of an abstraction that works most of the time, but where a detail of the underlying complexity cannot be ignored, thus leaking complexity out of the abstraction back into the software that uses the abstraction.
History
The term "leaky abstraction" was popularized in 2002 by
Joel Spolsky
Avram Joel Spolsky (born 1965) is a software engineer and writer. He is the author of ''Joel on Software'', a blog on software development, and the creator of the project management software Trello. He was a Program Manager on the Microsoft Exce ...
.
An earlier paper by
Kiczales describes some of the issues with imperfect abstractions and presents a potential solution to the problem by allowing for the customization of the abstraction itself.
Effect on software development
As systems become more complex, software developers must rely upon more abstractions. Each abstraction tries to hide complexity, letting a developer write software that "handles" the many variations of modern computing.
However, this law claims that developers of ''reliable'' software must learn the abstraction's underlying details anyway.
Examples
Spolsky'
articlecites many examples of leaky abstractions that create problems for software development:
* The
TCP/IP
The Internet protocol suite, commonly known as TCP/IP, is a framework for organizing the set of communication protocols used in the Internet and similar computer networks according to functional criteria. The foundational protocols in the suit ...
protocol stack is the combination of
TCP, which tries to provide reliable delivery of information, running on top of
IP, which provides only 'best-effort' service. When IP loses a packet TCP has to retransmit it, which takes additional time. Thus TCP provides the abstraction of a reliable connection, but the implementation details leak through in the form of potentially variable performance (throughput and latency both suffer when data has to be retransmitted), and the connection can still break entirely.
*
Iterating over a large two-dimensional
array
An array is a systematic arrangement of similar objects, usually in rows and columns.
Things called an array include:
{{TOC right
Music
* In twelve-tone and serial composition, the presentation of simultaneous twelve-tone sets such that the ...
can have radically different performance if done horizontally rather than vertically, depending on the order in which elements are stored in memory. One direction may vastly increase
cache misses
In computing, a cache ( ) is a hardware or software component that stores data so that future requests for that data can be served faster; the data stored in a cache might be the result of an earlier computation or a copy of data stored elsewher ...
and
page fault
In computing, a page fault (sometimes called PF or hard fault) is an exception that the memory management unit (MMU) raises when a process accesses a memory page without proper preparations. Accessing the page requires a mapping to be added to t ...
s, both of which greatly delay access to memory.
* The
SQL language abstracts away the procedural steps for querying a
database
In computing, a database is an organized collection of data stored and accessed electronically. Small databases can be stored on a file system, while large databases are hosted on computer clusters or cloud storage. The design of databases sp ...
, allowing one to merely define what one wants. But certain SQL queries are thousands of times slower than other logically equivalent queries. On an even higher level of abstraction,
ORM
Orm (in Old Norse and in modern Danish, Swedish, Norwegian (bokmål and nynorsk) the word for "snake", "worm" or "dragon") became an Anglo-Saxon personal name during period of the Danelaw.
Orm may also refer to:
* Orm or Ormin, the author of ...
systems, which isolate object-oriented code from the implementation of object persistence using a relational database, still force the programmer to think in terms of databases, tables, and native SQL queries as soon as performance of ORM-generated queries becomes a concern.
* Although network file systems like
NFS and
SMB let one treat files on remote machines as if they were local, the connection to the remote machine may slow down or break, and the file stops acting as if it were local.
* The
ASP.NET
ASP.NET is an open-source, server-side web-application framework designed for web development to produce dynamic web pages. It was developed by Microsoft to allow programmers to build dynamic web sites, applications and services. The name s ...
web forms programming platform, not to be confused with ASP.NET MVC, abstracts away the difference between HTML code to handle clicking on a hyperlink (
) and code to handle clicking on a button. However, ASP.NET needs to hide the fact that in HTML there is no way to submit a form from a hyperlink. It does this by generating a few lines of JavaScript and attaching an onclick handler to the hyperlink. However, if the end user has JavaScript disabled, the ASP.NET application malfunctions. Furthermore, one cannot naively think of event handlers in ASP.NET in the same way as in a desktop GUI framework such as
Windows Forms
Windows Forms (WinForms) is a free and open-source graphical (GUI) class library included as a part of Microsoft .NET, .NET Framework or Mono Framework, providing a platform to write client applications for desktop, laptop, and tablet PCs. While ...
; due to the asynchronous nature of the Web, processing event handlers in ASP.NET requires exchanging data with the server and reloading the form.
Git's interface is another example for leaky abstraction as explained in this article.
See also
*
Abstraction inversion
In computer programming, abstraction inversion is an anti-pattern arising when users of a construct need functions implemented within it but not exposed by its interface. The result is that the users re-implement the required functions in terms of ...
*
Dependency inversion principle
In object-oriented design, the dependency inversion principle is a specific methodology for loosely coupling software modules. When following this principle, the conventional dependency relationships established from high-level, policy-settin ...
*
Essential complexity
Essential complexity is a numerical measure defined by Thomas J. McCabe, Sr., in his highly cited, 1976 paper better known for introducing cyclomatic complexity. McCabe defined essential complexity as the cyclomatic complexity of the reduced CFG ( ...
*
Modular programming
Modular programming is a software design technique that emphasizes separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired function ...
*
Separation of concerns
In computer science, separation of concerns is a design principle for separating a computer program into distinct sections. Each section addresses a separate '' concern'', a set of information that affects the code of a computer program. A concern ...
References
{{DEFAULTSORT:Leaky Abstraction
Abstraction