Language-Oriented Programming Via Dsl Stacking
Total Page:16
File Type:pdf, Size:1020Kb
LANGUAGE-ORIENTED PROGRAMMING VIA DSL STACKING Bernhard G. Humm Darmstadt University of Applied Sciences, Department of Computer Science, Darmstadt, Germany Ralf S. Engelschall Capgemini sd&m Research, Munich, Germany Keywords: Language-oriented programming, Extensible programming languages, Domain-specific languages, Meta pro- gramming, Semantic web, Business information systems, Lisp. Abstract: According to the paradigm of Language-Oriented Programming, an application for a problem should be im- plemented in the most appropriate domain-specific language (DSL). This paper introduces DSL stacking, an efficient method for implementing Language-Oriented Programming where DSLs and general-purpose lan- guages are incrementally developed on top of a base language. This is demonstrated with components of a business information system that are implemented in different DSLs for Semantic Web technology in Lisp. 1 INTRODUCTION purpose. Like all software engineering paradigms, When analyzing large-scale commercial IT projects Language-Oriented Programming ultimately serves today, you usually find that five or even more lan- one goal: to allow for developing applications of guages are being used – even in a “pure Java project” high-quality at reasonable cost. To this end, which if you take a closer look. HTML and JavaScript may criteria do we expect from a DSL most appropriate be used for GUI programing, SQL or EJBQL for for a particular domain and why? database accesses, UML for data modeling, Perl for Sufficient Semantic Expressiveness. The DSL the UML to Java generator, BPEL for process logic must allow to express logic necessary for the and several XML dialects for configuration. Why respective application domain directly in the would projects put up with the high costs of hetero- language, e.g., rules in a knowledge-based geneity? This is because different problem domains system. This is necessary for implementing the require different language constructs. application at all. This is the main idea of a paradigm called Language-Oriented Programming (Ward, 1994; Conciseness and Comprehensibility. Statements Fowler, 2005; Dmitriev, 2005; Brauer et al., 2008). should be expressed adequately, i.e., as concisely It can be briefly summarized as follows. When you and comprehensibly as possible. Boilerplate code have to solve a complex problem, first choose – should be avoided. Inadequate representation has or, if necessary, develop – a language that is most several drawbacks. Firstly, developing unneces- appropriate for the problem. Then, implement the sarily voluminous code increases the costs for de- solution in this language. veloping the application. Even higher are the In most publications today, such a language follow-up costs for maintenance. Secondly, the is called a Domain-Specific Language (DSL) (van quality of the solution decreases since errors can- Deursen et al., 2000) – see Sect. 5.2. Earlier pub- not be detected as easily. The more adequate the lications use the term Problem-Oriented Language representation – i.e., the closer to the problem do- (Goldfinger, 1961). In this paper we stick to the term main – the more problem domain experts can be DSL although it shall be noted that the problem area involved in the development. does not have to be a business domain and the lan- Integration. It must be possible to integrate the DSL guage may be more or less specific, depending on its application with other applications, possibly im- 279 G. Humm B. and S. Engelschall R. (2010). LANGUAGE-ORIENTED PROGRAMMING VIA DSL STACKING. In Proceedings of the 5th International Conference on Software and Data Technologies, pages 279-287 DOI: 10.5220/0002925402790287 Copyright c SciTePress ICSOFT 2010 - 5th International Conference on Software and Data Technologies plemented in other DSLs. This includes invoca- DSLs. The Unix little languages like AWK (Aho tion at run-time and, ideally, integrated develop- et al., 1988) or make (Feldman, 1979) are examples ment including integrated debugging. Integration of DSLs. is mandatory if the DSL application is a compo- Recently, there have evolved a number of nent of a larger application, e.g., a business infor- Language-Oriented Programming initiatives. Apart mation system. Integrated development decreases from OMG’s MDA initiative these are the STEPS development costs, particularly for testing and de- project (Kay et al., 2008), Microsoft’s “Software bugging. Factories” (Greenfield, 2004), “Intentional Program- Performance. Applications implemented in the DSL ming” (Simonyi et al., 2006) and the “Meta- must meet the respective performance require- Programming System” (Dmitriev, 2005). In those ments. publications, the term “language workbench” is used as an integrated environment to design and implement Those aspects help the application developer (de- DSLs and to program applications in those DSLs. signer and implementer). Language-Oriented Pro- Additionally, a number of new extensible pro- graming adds another role: the language developer gramming languages like F#, Ruby, Groovy, and (designer and implementer). The following aspect Scala have evolved in the last decade. They explicitly helps the language developer. provide features for language-oriented programming Efficient DSL Development. The design, imple- like Groovy’s Meta-Object Protocol (MOP). mentation including validation logic, testing, and Two approaches to Language-Oriented Program- maintenance of DSLs should be as efficient as ming can be distinguished: external DSLs and inter- possible. Efficient DSL development directly af- nal DSLs (Fowler, 2005). fects the total development cost. Internal DSLs are idiomatic ways of writing higher- In this paper, we present a method for Language- level language code in the host language of the Oriented Programming called DSL Stacking. DSL application (“base language” – see Sect. 5.2) stacking may meet all the criteria described above. directly. Example: AllegroProlog, a Prolog We demonstrate this with a sample Lisp application (Clocksin and Mellish, 1987) implementation by using Semantic Web technology in the insurance busi- Franz Inc. fully integrated in Lisp that allows Pro- ness. log programming in Lisp notation. The extensible This article is structured as follows. Sect. 2 and programming language initiatives all fall into this 3 give an overview of Language-Oriented Program- category. ming, Semantic Web technology, the insurance sam- External DSLs are different from the base language. ple and Lisp. In Sect. 4 we present a family of DSLs DSL programs are scanned, parsed and trans- for applying Semantic Web technology in the insur- formed into the base language using some form of ance business. Sect. 5 explains the concept of DSL compiler or interpreter. Example: a BPEL (OA- stacking. In Sect. 6, we discuss the results. Sect. 7 SIS, 2007) engine parses XML code and trans- concludes this article. forms it into data structures of a programming lan- guage like Java. The Unix little languages and MDA fall into this category. External DSLs may be embedded in a host language, e.g., as strings, 2 LANGUAGE-ORIENTED or may be programmed in separate files. PROGRAMMING In this paper, we focus on internal DSLs. The term Language-Oriented Programming (Ward, 1994; Fowler, 2005; Dmitriev, 2005; Brauer et al., 2008) has already been used for a number of years. 3 SAMPLE DOMAIN: SEMANTIC The idea, however, is even much older and has been WEB TECHNOLOGY IN THE around since the invention of the first high-level pro- gramming languages. There have been a number INSURANCE BUSINESS of extensible language initiatives in the 1960 and 1970s, e.g, translator writing systems like “The Syn- 3.1 Semantic Web Standards tax Directed Compiler” (Irons, 1961) or extensible programming languages like Lisp (McCarthy, 1960), The World Wide Web Consortium (W3C) has stan- IMP (Irons, 1970), and Smalltalk-72 (Kay, 1993). dardized a number of languages under the term “Se- Extensible languages facilitate the development of mantic Web” (Berners-Lee et al., 2001). The lan- 280 LANGUAGE-ORIENTED PROGRAMMING VIA DSL STACKING guages are based on the technologies XML and URI. insurance-example#Heart-Stroke"> The main Semantic Web standards are as follows </rdf:Description> (World Wide Web Consortium (W3C), 2010). </ins:has-disease> </rdf:Description> RDF (Resource Description Framework) is the ba- </rdf:RDF> sic Semantic Web modeling language. The funda- Ten lines of XML code are necessary for expressing mental data structure is a triple consisting of sub- a simple triple. With this verbose code, RDF/XML ject, predicate, and object. is certainly no adequate representation for Semantic RDF-S (RDF Schema) builds on top of RDF adding Web programming. Other representations more or the concepts of classes and properties. less alleviate shortcomings of RDF/XML to provide a more concise and human-comprehensible form – one OWL (Web Ontology Language) builds on top of of the main concerns of Language-Oriented Program- RDF-S and adds expressive set-based logic. ming. SPARQL (SPARQL Protocol and RDF Query Lan- guage) allows for querying RDF-S and OWL 3.4 Business Domain: Insurance statements. We have developed a family of DSLs and have imple- 3.2 RDF Triples mented an insurance example application using those DSLs. The example is about issuing disability insur- The triple is the basic yet powerful data structure of ance. The customer interested in a disability insur- RDF. Every triple consists of subject, predicate, and ance must provide, apart from personal data, infor- object. See Figure 1. It allows for basic statements mation about employment, financial situation, health, like “Peter has an income of $ 65,000”. It further- and lifestyle. Based on this situation, the applica- more allows statements about class / instance rela- tion will perform a customer rating. For example, se- tionships as in “Peter is a Person” and “Person is a vere diseases present in the family history may lead to Class”. It also allows statements about properties like the decision of not offering a policy to the applicant. “has-income is a Property”. Based on the rating, the application automatically ac- cepts or declines the application or involves human Peter has-income 65,000 intervention.