Semantic Properties for Lightweight Specification in Knowledgeable

Semantic Properties for Lightweight Specification in Knowledgeable

Semantic Properties for Lightweight Specification in Knowledgeable Development Environments Joseph R. Kiniry Department of Computer Science California Institute of Technology Mailstop 256-80 Pasadena, CA 91125 [email protected] ABSTRACT 1. INTRODUCTION Semantic properties are domain-specific specification con- Ad hoc constructs and local conventions have been used to structs used to augment an existing language with richer se- annotate program code since the invention of programming mantics. These properties are taken advantage of in system languages. The purpose of these annotations is to convey ex- analysis, design, implementation, testing, and maintenance tra programmer knowledge to other system developers and through the use of documentation and source-code transfor- future maintainers. These comments usually fall into that mation tools. Semantic properties are themselves specified gray region between completely unstructured natural lan- at two levels: loosely with precise natural language, and for- guage and formal specification. mally within the problem domain. The refinement relation- ships between these specification levels, as well as between a Invariably, such program comments rapidly exhibit “bit rot”. semantic property’s use and its realization in program code Over time, these comments, unless well maintained by doc- via tools, is specified with a new formal method for reuse umentation specialists, rigorous process, or other extra-mile called kind theory. development efforts, become out-of-date. They are the focus for the common mantra: an incorrect comment is worse than no comment at all. Categories and Subject Descriptors D.1.0 [Software]: Programming Techniques—General; D.2 Recently, with the adoption and popularizationof lightweight [Software]: Software Engineering; D.3.1 [Software]: Pro- documentationtools in the literate programmingtradition [17, gramming Languages—Formal Definitions and Theory; D.3.2 18], an ecology of semi-structured comments is flourishing. [Software]: Programming Languages—Language Classifi- The rapid adoption and popularity of Java primed interest cations [design languages]; D.3.4 [Software]: Programming in semi-structured comment use via the Javadoc tool. Other Languages—Processors [preprocessors]; F.3.1 [Theory of similar code-to-documentationtransformation tools have since Computation]: Logics and Meanings of Programs—Spec- followed in volume including Jakarta’s Alexandria, Doxy- gen, and Apple’s HeaderDoc. SourceForge1 reports thirty- ifying and Verifying and Reasoning about Programs; F.4.1 2 [Theory of Computation]: Mathematical Logic and Formal six projects with “Javadoc” in the project summary. FreshMeat Languages—Mathematical Logic; F.4.3 [Theory of Com- reports another thirty-five, with some overlap. putation]: Mathematical Logic and Formal Languages— Formal Languages While most of these systems are significantly more simple than Knuth’s original CWEB, they share two key features. First, they are easy to learn, since they necessitate only a General Terms small change in convention and process. Rather than forcing arXiv:cs/0204035v1 [cs.SE] 15 Apr 2002 documentation, semantic properties, specification languages, the programmer to learn a new language, complex tool, or formal methods, kind theory, specification reuse, documen- imposing some other significant barrier to use, these tools tation reuse actually reward the programmer for documenting her code. Second, a culture of documentationis engendered. Prompted by the example of vendors like Sun, programmers enjoy the creation and use of the attractive automatically-generated documentation in a web page format. This documentation- centric style is only strengthened by the exhibitionist nature 1 FSE-10 2002 Charleston, South Carolina, USA http://www.sf.net/ 2http://www.freshmeat.net/ of the Web. Having the most complete documentation is 2.1 Documentation Semantics now a point of pride in some Open Source projects; a state Recently, Sun has started to extend the semantics of these of affairs we would not have guessed at a decade ago. basic properties with respect to language semantics, particu- larly with regards to inheritance. If a class C inherits from a The primary problem with these systems, and the documen- parent class P , and P ’s method m has some documentation, tation and code written using them, is that even semi-structured but C’s overridden or effective (in the case where P and/or comments have no semantics. Programmers are attempting m is abstract) version of m does not, then Javadoc inherits to state (sometimes quite complex) knowledge but are not C.m’s documentation for P.m, generating the appropriate given the language and tools with which to communicate comments in Javadoc’s output. this knowledge. And since the vast majority of developers are unwilling to learn a new, especially formal, language This change in behavior of the tools is an implicit change in with which to convey such information, we must look for the semantics of the documentation. While straightforward a happy-medium of informal formality. and useful in this example, the meaning of such inheritance is undocumented and often unclear. That compromise, the delicate balance between informality and formality, and the lightest-weight aspect of our Knowl- The situation in Eiffel is less confusing. The semantics of edgeable Software Engineering program, is what we call se- properties, as realized by indexing clauses and formal pro- mantic properties. gram annotation via contracts, are defined in the language standard [23]. Semantic properties are domain-independent documentation constructs with intuitive formal semantics that are mapped Even so, no mechanism exists in either system for extending into the semantic domain of their application. Semantic prop- these semi-structured comments with new semantics beyond erties are used as if they were normal semi-structured docu- simple plug-ins for documentation (e.g., doclets in Java and mentation. But, rather than being ignored by compilers and translators in EiffelStudio). development environments as comments typically are, they have the attention of augmented versions of such tools. Se- Also, the semantics of current annotations are entirely spec- mantic properties embed a tremendous amount of concise ified within a particular language or formalism. No gen- information wherever they are used without imposing the of- eral purpose formalism has been used to express their extra- ten insurmountable overhead seen in the introduction of new model semantics. languages and formalisms for similar purposes. 2.2 Semantics of Semantic Properties We specify the semantics of semantic properties in a new 2. SEMANTIC PROPERTIES formalism called kind theory. Kind theory is a logic used to The original inspiration for semantic properties came from describe, reason about, and discover reusable assets of arbi- three sources: the use of tags, (e.g., @author and @param), trary sorts. Kind theory is an higher-order, autoepistemic4, in the Javadoc system, the use of annotations and pragmas paraconsistent5, categorical logic with a type theoretic and in languages like Java and C for code transformation and algebraic model, and is described in full detail in Kiniry’s guided compilation, and indexing clauses in Eiffel. All of dissertation [15]. these systems have a built-in property-value mechanism, one at the documentation level and one within the language syn- 2.2.1 A Brief Overview of Kind Theory tax itself, that is used to specify semi-structured information. Kind are classifiers used to describe reusable assets like pro- gram code, components, documentation, specifications, etc. In Java, tags are the basic realization of our semantic proper- Instances are realizations of kind—actual embodiments of ties. They are used for documentation and formal specifica- these classifiers. For example, the paperback “The Portrait tion, as we will discuss in more detail in Section 3.1.1. Tags of the Artist as a Young Man” by James Joyce is an in- are not part of the language specification. In fact, they are stance of kinds PAPERBACKBOOK, ENGLISHDOCUMENT, entirely ignored by all Java compilers. and others. Annotations and pragmas come in the form of formal tags 3 In the context of semantic properties, our kinds are the se- used for some Design by Contract tools like Jass which mantic properties as well as the programming language con- happen to be realized in Eiffel with first-class keywords like structs to which the properties are bound. Our instances are require, ensure, and invariant. the specific realizations of these kinds within a particular in- put structure, typically a programming or specification lan- Eiffel provides first-class support for properties via indexing guage. clauses. An Eiffel file can contain arbitrary property-value pairs inside of indexing blocks. This information is used Kinds are described structurally using our logic in a num- by a variety of tools for source code search, organization, ber of ways. Classification is covered with the inheritance and documentation. 4Auto-epistemic: “representing or discussing self-knowledge”. 5Paraconsistent: “explicitly representing and reasoning with poten- 3http://semantik.informatik.uni-oldenburg.de/ jass/ tial and transitory logic inconsistency”. operators < and <p; structural relationships are formalized the contexts in which a kind can be used and how kinds are using the inclusion operators ⊂p and ⊃, equivalence has sev- composed to create new kinds. We discuss structural rela- eral forms ≖ and ⋖; realization,

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    10 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us