Prev Next

Issues in Programming Language Design [Chapter 1]

Goals in language design

  • Ease of programming
  • Portability
  • Reliability
  • Modifiability
  • Efficiency

There are often tradeoffs. For example, if you want the greatest efficiency, you would use assembly language. All other goals would suffer.

Development of programming languages

  1. Machine language

  2. Assembly language: one-for-one with machine language

  3. Fortran: One statement abbreviates several machine language instructions

  4. Higher level languages: moving away from the raw machine

  5. Mathematical languages: based on mathematics rather than computers

General rules for designing programming languages

  • Use regular rules, with few, if any, exceptions. Orthogonality: any kind of statement or expression should be allowed whereever any other kind is allowed.

    Violation: C++
    n++ is an expression. n = E; is an assignment statement that evaluates expression E and stores the result into variable n. So you would expect that
        n = n++;
    
    would evaluate expression n++ and store the result into variable n. But the definition of ANSI C++ says that this is an exception to the general rule. A compiler is allowed to make this statement do something quite different from what you expect.

  • Use familiar notation. But regularity and simplicity is often more important than this.

  • Avoid confusing or misleading notation. Avoid cases where one thing looks like another.

    Violation: C++
    
        double x = 1/3;
    
    stores 0 into x, not 0.333333333.

    Violation: C++
    
        if(x = y) ...
    
    does not test whether x and y are the same.

    Violation: Fortran
    
            DO 10 I = 1,100
              RUN(I)
        100 CONTINUE
    
    is a loop that does RUN(1), RUN(2), ..., RUN(100). But
    
            DO 10 I = 1.100
              RUN(I)
        100 CONTINUE
    
    only does RUN(1). The first line is an assignment statement that sets variable DO10I to hold 1.1.

  • Provide operations that the programmer finds useful. This leads to large libraries.

  • Allow long, descriptive names. Early Fortran: only 6 characters in a name. Early Basic: only 2 characters.

  • Avoid needless duplication of features.

Modification and encapsulation

The majority of the time, programmers are modifying existing programs rather than starting new ones. A programming language should provide features to ease modification. The usual method is to use encapsulations.

An encapsulation hides certain things inside itself, so that the programmer knows that those things are not visible from outside. Any modification to the hidden things only affects that one encapsulation.

Examples of encapsulations are:

  • Named constants. These hide the value of the constant.

  • Functions. These hide the method by which they work.

  • Modules. These hide some of their functions and variables.

  • Types. These can hide how data is represented, if they are designed carefully.

  • Classes. These are a combination of several things, including aspects of modules and types. They can hide functions, variables and data representations.

Useful concepts for encapsulation are intension and extension. The intension describes the visible aspects of something, what it is intended to do or to represent. The extension tells how that thing is implemented now (possibly to be changed tomorrow). Working with intensions instead of extensions makes programs more modifiable.

Reusable software

Programming languages should facilitate producing reusable libraries. To be useful, libraries must be as general as possible. They should handle

  • Arrays of arbitrary size
  • Often, arrays of arbitrary types of things
  • Sometimes, any type of thing that has certain capabilities

Because of the need for generality, libraries tend to put the most stress on programming language design.


Prev Next