HOME

TheInfoList



OR:

In
software engineering Software engineering is a systematic engineering approach to software development. A software engineer is a person who applies the principles of software engineering to design, develop, maintain, test, and evaluate computer software. The term ' ...
and
programming language theory Programming language theory (PLT) is a branch of computer science that deals with the design, implementation, analysis, characterization, and classification of formal languages known as programming languages. Programming language theory is clo ...
, the abstraction principle (or the principle of abstraction) is a basic
dictum In general usage, a dictum ( in Latin; plural dicta) is an authoritative or dogmatic statement. In some contexts, such as legal writing and church cantata librettos, ''dictum'' can have a specific meaning. Legal writing In United States legal te ...
that aims to reduce duplication of information in a program (usually with emphasis on
code duplication In computer programming, duplicate code is a sequence of source code that occurs more than once, either within a program or across different programs owned or maintained by the same entity. Duplicate code is generally considered undesirable for a nu ...
) whenever practical by making use of
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 a ...
s provided by the programming language or
software libraries In computer science, a library is a collection of non-volatile resources used by computer programs, often for software development. These may include configuration data, documentation, help data, message templates, pre-written code and subro ...
. The principle is sometimes stated as a recommendation to the programmer, but sometimes stated as a requirement of the programming language, assuming it is self-understood why abstractions are desirable to use. The origins of the principle are uncertain; it has been reinvented a number of times, sometimes under a different name, with slight variations. When read as recommendations to the programmer, the abstraction principle can be generalized as the "
don't repeat yourself "Don't repeat yourself" (DRY) is a principle of software development aimed at reducing repetition of software patterns, replacing it with abstractions or using data normalization to avoid redundancy. The DRY principle is stated as "Every piece o ...
" (DRY) principle, which recommends avoiding the duplication of information in general, and also avoiding the duplication of human effort involved in the software development process.


The principle

As a recommendation to the programmer, in its formulation by
Benjamin C. Pierce Benjamin Crawford Pierce is the Henry Salvatori Professor of computer science at the University of Pennsylvania. Pierce joined Penn in 1998 from Indiana University and held research positions at the University of Cambridge and the University of E ...
in '' Types and Programming Languages'' (2002), the abstraction principle reads (emphasis in original): As a requirement of the programming language, in its formulation by David A. Schmidt in ''The structure of typed programming languages'' (1994), the abstraction principle reads:.


History and variations

The abstraction principle is mentioned in several books. Some of these, together with the formulation if it is succinct, are listed below. * Alfred John Cole, Ronald Morrison (1982) ''An introduction to programming with S-algol'': " bstractionwhen applied to language design is to define all the semantically meaningful syntactic categories in the language and allow an abstraction over them". * Bruce J. MacLennan (1983) ''Principles of programming languages: design, evaluation, and implementation'': "Avoid requiring something to be stated more than once; factor out the recurring pattern". * Jon Pearce (1998) ''Programming and Meta-Programming in Scheme'': "Structure and function should be independent". The principle plays a central role in design patterns in
object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of " objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of ...
, although most writings on that topic do not give a name to the principle. The Design Patterns book by the Gang of Four, states: "The focus here is '' encapsulating the concept that varies'', a theme of many design patterns." This statement has been rephrased by other authors as "Find what varies and encapsulate it." In this century, the principle has been reinvented in
extreme programming Extreme programming (XP) is a software development methodology intended to improve software quality and responsiveness to changing customer requirements. As a type of agile software development,"Human Centred Technology Workshop 2006 ", 2006, P ...
under the slogan "Once and Only Once". The definition of this principle was rather succinct in its first appearance: "no duplicate code". It has later been elaborated as applicable to other issues in software development: "Automate every process that's worth automating. If you find yourself performing a task many times, script it."


Implications

The abstraction principle is often stated in the context of some mechanism intended to facilitate abstraction. The basic mechanism of control abstraction is a function or
subroutine In computer programming, a function or subroutine is a sequence of program instructions that performs a specific task, packaged as a unit. This unit can then be used in programs wherever that particular task should be performed. Functions ma ...
. Data abstractions include various forms of
type polymorphism In programming language theory and type theory, polymorphism is the provision of a single interface to entities of different types or the use of a single symbol to represent multiple different types.: "Polymorphic types are types whose operatio ...
. More elaborate mechanisms that may combine data and control abstractions include:
abstract data type In computer science, an abstract data type (ADT) is a mathematical model for data types. An abstract data type is defined by its behavior (semantics) from the point of view of a '' user'', of the data, specifically in terms of possible values, po ...
s, including classes,
polytypism Many compound materials exhibit polymorphism, that is they can exist in different structures called polymorphs. Silicon carbide (SiC) is unique in this regard as more than 250 polymorphs of silicon carbide had been identified by 2006, with some of ...
etc. The quest for richer abstractions that allow less duplication in complex scenarios is one of the driving forces in programming language research and design. Inexperienced programmers may be tempted to introduce too much abstraction in their program—abstraction that won't be used more than once. A complementary principle that emphasizes this issue is " You Ain't Gonna Need It" and, more generally, the
KISS principle KISS, an acronym for "Keep it simple, stupid!", is a design principle noted by the U.S. Navy in 1960. First seen partly in American English by at least 1938, the KISS principle states that most systems work best if they are kept simple rather th ...
. Since code is usually subject to revisions, following the abstraction principle may entail
refactoring In computer programming and software design, code refactoring is the process of restructuring existing computer code—changing the '' factoring''—without changing its external behavior. Refactoring is intended to improve the design, structu ...
code. The effort of rewriting a piece of code generically needs to be amortized against the estimated future benefits of an abstraction. A rule of thumb governing this was devised by Martin Fowler, and popularized as the rule of three. It states that if a piece of code is copied more than twice, i.e. it would end up having three or more copies, then it needs to be abstracted out.


Generalizations

"
Don't repeat yourself "Don't repeat yourself" (DRY) is a principle of software development aimed at reducing repetition of software patterns, replacing it with abstractions or using data normalization to avoid redundancy. The DRY principle is stated as "Every piece o ...
", or the "DRY principle", is a generalization developed in the context of multi-tier architectures, where related code is by necessity duplicated to some extent across tiers, usually in different languages. In practical terms, the recommendation here is to rely on automated tools, like code generators and data transformations to avoid repetition.


Hardware programming interfaces

In addition to optimizing code, a hierarchical/recursive meaning of Abstraction level in programming also refers to the interfaces between hardware communication layers, also called "abstraction levels" and "abstraction layers." In this case, level of abstraction often is synonymous with interface. For example, in examining shellcode and the interface between higher and lower level languages, the level of abstraction changes from operating system commands (for example, in C) to register and circuit level calls and commands (for example, in assembly and binary). In the case of that example, the boundary or interface between the abstraction levels is the stack.Koziol, ''The Shellcoders Handbook"'', Wiley, 2004, p. 10,


References

{{reflist Programming language topics Programming principles