• Keine Ergebnisse gefunden

Modeling Languages, Programming Languages, and DSLs

2.2 Software Language Engineering

2.2.4 Modeling Languages, Programming Languages, and DSLs

When speaking about software languages, it is often distinguished between different kinds of languages, e.g., programming languages, modeling languages, and DSLs. In the follow-ing subsections, we define those terms usfollow-ing the previously defined language concepts.

7In some computer science literature, the term ‘conceptual model’ is specifically used for what we defined as a domain model. For us, a domain model is a specific kind of a conceptual model.

28 Chapter 2. Foundations Modeling Languages & Programming Languages

Often, a distinction is made between modeling languages and programming languages.

In many cases this distinction is based on the perceived level of abstraction. Modeling languages such as UML are often described as providing a higher level of abstraction than typical programming languages such as C++ which let you express fine-grained implementation details. However, as this is rather subjective and also gradual (e.g., Java abstracts more from the hardware than C++), we will not distinguish between modeling languages and programming languages based on the level of abstraction. Every language utterance abstracts from the real world by using simplified concepts defined by the lan-guage. Consequently, we have defined that every language utterance is a model. For us, every software language is a modeling language because it is used to create models.

However, there is another way to distinguish between a modeling and a programming language. Programming languages are usually executable whereas modeling languages are not necessarily executable. Modeling languages are often described more generally as languages that allow expressing structured data in a well-defined way. We follow this distinction and align it with our distinction between execution semantics and structure-only semantics. Thus, we define the term ‘programming language’ to be synonymous with

‘executable language’, i.e., a language which provides execution semantics:

Definition 2.21 (programming language, executable language). Aprogramming language is anexecutable language. An executable language is a language with execution semantics.

As mentioned before, execution semantics also often define structure. Thus, program-ming languages are also often modeling languages (e.g., we can use Java to describe an object structure) but modeling languages are often no programming languages. One can, however, define execution semantics for any modeling language to make it a programming language. Based on the definition of programming language we define what a program is.

Definition 2.22 (program). A program is an utterance of a programming language.

This is consistent with the traditional definition of a program to be a set of instructions.

The elements of the internal structure of a programming language utterance can be transformed into or serve themselves as instructions for a machine. Consequently, every program is a conceptual model (a model of the machine yielded by passing the program to a programmable machine) but not every model is a program that can be executed.

Domain-Specific Languages & General-Purpose Languages

Another common distinction among software languages is that betweengeneral-purpose languages(GPLs) anddomain-specific languages (DSLs, formerly also referred to aslittle languages, Bentley, 1986). The general understanding of this distinction is that a DSL is a language which is tailored to a narrow application domain, so the variety of problems it can be applied to is rather limited, whereas a GPL has a wider application domain which potentially subsumes several more specific domains (Spinellis, 2001; Landin, 1966). Thus, a GPL is more versatile. However, this again is a gradual distinction. A language can

2.2. Software Language Engineering 29 be more or less domain-specific. In a certain sense, every language has a limited domain and thus is domain-specific. Ideally, we would be able to compare languages by the size of their application domain. However, there is no agreement on how to measure the size of an application domain. One could say that a domain which contains all elements of another, plus more elements, is bigger (i.e., there is a subset relation). However, such a subset relation cannot be defined for disjunct domains. Therefore, we define what a DSL is in terms of its goals.

The main goal of a DSL is to be particularlyexpressivein its domain, in the sense that more can be said with less. This is possible because with a narrow application domain, one can agree on more implicit assumptions and less has to be stated explicitly. This way, domain concepts can be expressed concisely. Thus, a DSL can achieve a higher level of abstraction within its domain than a GPL at the cost of being less versatile. The goal of this abstraction is efficient communication of domain knowledge. Like a model, a DSL tailored to one domain should not be used to describe knowledge in another domain because made assumptions may not be true. This is known as themodeling gap.

However, abstraction is not the only goal of a DSL and there may be DSLs which do not provide more abstraction than a GPL at all. The other goal of a DSL is the limitation itself which can help to prevent users of the DSL to create models that do not make sense in the particular domain. Also, the limitation allows language tooling to provide better user assistance, as the assistance can be better tailored for the domain. As there is no general agreement in the literature on what a DSL is exactly8, we define it by its goals.

Definition 2.23 (domain-specific language). A domain-specific language (DSL) is a lan-guage with a narrow application domain. Its goals are to be particularly expressive in its domain, and to prevent users from creating models which make no sense in that domain.

Definition2.24 (domain-specific model). Adomain-specific model is a language utterance of a domain-specific language.

A good example of a DSL according to the above definition is SQL. Database queries can be expressed much more concisely than, say, a general-purpose programming lan-guage like Java. Furthermore, it is hard to express anything else in SQL than database queries. Implementing an application with a graphical user interface (which is a different application domain) is hardly possible using SQL because one cannot describe a con-stantly running user input loop. Take on the other hand an assembly language for an x86 processor. It is a general-purpose language whose application domain is only limited by the processor architecture. One can implement a wide range of applications, includ-ing graphical user interfaces and database queries. However, describinclud-ing a database query would need lots of assembly code. Thus, it is not very expressive in that domain.

Combining the distinction between GPLs and DSLs with the distinction between pro-gramming and modeling languages, one could speak of general-purpose propro-gramming languages, general-purpose modeling languages, domain-specific programming languages,

8e.g., see M. Fowler’s discussion about a general definition: http://martinfowler.com/bliki/DslBoundary.html

30 Chapter 2. Foundations and domain-specific modeling languages. Java, Scala, C++, etc. are examples of general-purpose programming languages because they are versatile and executable. SQL, being also executable, could be considered a domain-specific programming language. UML is an example for general-purpose modeling language, as it is very versatile but not exe-cutable. Such a modeling language can be provided with execution semantics, as shown byExecutable UML, which makes it a programming language according to our definition.

HTML could be considered an example of a domain-specific modeling language, because it has structure-only semantics and is specifically tailored for describing web pages.