User Tools

Site Tools


principles:law_of_leaky_abstractions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
principles:law_of_leaky_abstractions [2013-08-29 12:15]
christian
principles:law_of_leaky_abstractions [2013-10-08 11:09]
christian
Line 13: Line 13:
 > All non-trivial abstractions,​ to some degree, are leaky.((Joel Spolsky: //​[[http://​joelonsoftware.com/​articles/​LeakyAbstractions.html|The Law of Leaky Abstractions]]//​)) > All non-trivial abstractions,​ to some degree, are leaky.((Joel Spolsky: //​[[http://​joelonsoftware.com/​articles/​LeakyAbstractions.html|The Law of Leaky Abstractions]]//​))
  
-A solution is bad if  +A solution is bad if 
-a) the leakiness of abstractions is ignored (bad usage of an abstraction) or +  ​* ​the leakiness of abstractions is ignored (bad usage of an abstraction) or 
-b) the benefits of the abstraction cannot justify the disadvantages created by its leakiness (bad abstraction) or +  ​* ​the benefits of the abstraction cannot justify the disadvantages created by its leakiness (bad abstraction) or 
-c) the abstraction is more leaky than necessary (bad abstraction)+  ​* ​the abstraction is more leaky than necessary (suboptimal ​abstraction)
  
 ===== Description ===== ===== Description =====
 +
 +Abstractions are typically not perfect. Especially performance aspects are very hard to abstract away from. So there are cases when using the abstraction properly is not possible without knowing the basics underneath the abstraction. So developing and, even more, fixing defects in a system with leaky abstractions makes it necessary to know about all the details the abstraction is supposed to protect the developers from. Often abstractions reduce the effort to develop a feature while they increase the effort for fixing bugs.
 +
 +A typical problem with leaky abstractions is that the leakiness is ignored. This does not directly mean that the abstraction itself is bad. Often the situation without the abstraction would be worse so it's good to have it. Nevertheless its unavoidable leaks have to be kept in mind. See [[#Example 1: Distributed Objects|example 1]].
 +
 +There are also situations where the abstraction is not crafted well. Sometimes there is a way to make the abstraction better (see [[#Example 2: String Classes In C++|example 2]]) but sometimes the whole abstraction is wrong and not having it would be better.
  
  
 ===== Rationale ===== ===== Rationale =====
-Abstractions ​are typically not perfectEspecially performance aspects are very hard to abstract away fromSo there are cases when using the abstraction properly ​is not possible without knowing the basics underneath the abstraction. So developing and even more fixing defects in system with leaky abstractions makes it necessary to know about all the details the abstraction is supposed to protect the developers fromOften abstractions reduce ​the effort ​to develop a feature while they increase ​the effort for fixing bugs. The benefits of an abstraction are only reached at the cost of some liabilities so an abstraction is only good when the liabilities are small enough compared to the benefits.+ 
 +  * Bad usages of abstractions ​are plain wrongThere is no doubt that they should be avoided. 
 +  * Suboptimal abstractions can be made better. There are unnecessary leaks and each leak is a possibility for a future usage fault (see [[Murphy'​s Law|ML]])As the leaks are unnecessary,​ there are ways to improve ​the abstraction so this one s bad. 
 +  * The benefits of an abstraction are only reached at the cost of some liabilities so an abstraction is only good when the liabilities are small enough compared to the benefits. ​Bad abstractions are worse than no abstraction at all, so they should not be employed. 
  
 ===== Strategies ===== ===== Strategies =====
Line 42: Line 52:
  
 Joel Spolsky: //​[[http://​joelonsoftware.com/​articles/​LeakyAbstractions.html|The Law of Leaky Abstractions]]//​ Joel Spolsky: //​[[http://​joelonsoftware.com/​articles/​LeakyAbstractions.html|The Law of Leaky Abstractions]]//​
 +
 +The blog article has another focus as it rather explains LLA as an effect rather than an engineering advice. Because abstractions are leaky, developers should and have to know the details abstractions try to protect them from. The principle aspect is only a side aspect there but the main focus here.
 +
  
 ===== Evidence ===== ===== Evidence =====
Line 73: Line 86:
 ===== Examples ===== ===== Examples =====
  
-==== Example 1: String Classes In C++ ====+==== Example 1: Distributed Objects ==== 
 + 
 +There is plenty of middleware which centers around the notion of distributed objects: RMI, CORBA, DCOM, ... These technologies abstract away from the fact that the objects are not local but distributed over the network. They create the illusion that calling all objects are local. But all these technologies are leaky abstractions. There is no way to abstract fro the fact that calling a remote object may fail. The network connection may break down, the remote machine may not be available, etc. Furthermore there are completely different performance characteristics of remote calls. There is some unavoidable latency and no abstraction what so ever can change this. 
 + 
 +This does not mean that these technologies are generally bad. There is a value in these abstractions but the leaks have to be kept in mind. Ignoring the fact that remote calls may fail will result in fragile systems. If the distributed system to develop should be robust, there has to be code handling failing remote calls. And for performance reasons, remote interfaces have to be crafted in a way that remote calls are minimized. So for example [[patterns:​Data Transfer Objects]] are employed in order to transfer larger chunks of data instead of making a remote call for every access to a getter method. 
 + 
 + 
 +==== Example 2: String Classes In C++ ====
  
 In C++ string literals such as ''"​test"''​ are of type ''​char*''​ which means pointer to a character. There is some range in the memory where a sequence of characters is stored and there is a pointer pointing to the first character. These strings are unhandy to use so there are string classes in C++ which abstract from these low-level strings which are simply a heritage of the C programming language C++ is built upon. These string classes are much more convenient to use and create the illusion of a built-in string type. In C++ string literals such as ''"​test"''​ are of type ''​char*''​ which means pointer to a character. There is some range in the memory where a sequence of characters is stored and there is a pointer pointing to the first character. These strings are unhandy to use so there are string classes in C++ which abstract from these low-level strings which are simply a heritage of the C programming language C++ is built upon. These string classes are much more convenient to use and create the illusion of a built-in string type.
principles/law_of_leaky_abstractions.txt · Last modified: 2018-04-11 11:57 by 84.46.93.199