User:Thepigdog/Programming Language Styles

Language Styles
There are several major families of languages
 * C and C++
 * Java
 * C#
 * D
 * Pascal
 * Delphi

The major difference between the C family and the Pascal family is in the syntax of the declarations,

The C++ family seems to be more popular because of its brevity. But it has the disadvantage that the type is not a separate element in the language. For example in,


 * long *(*MyFunctionPointer)(double p);

the type and declaration are all blended together.

The C++ language has a strange syntax for generic types (templates). This is tied to the implementation strategy used. Template classes are viewed as (textual) copies of classes. Logicaly a type parameter is no different from any other parameter.

The C++ family and the Pascal family styles may be generalised as,

The "->" symbol is used here instead of function,

The inheritance of a class should not have to be defined in the class declaration. In set theory the subset relationship may be defined in a statement,


 * $$A \subset B$$

So it makes sense to have an equivalent statement in a programming language. The following statements are equivalent,

Only virtual inheritance makes sense in a logical model. So there is no need for the virtual keyword. Private, protected, and public inheritance is rarely used in practice.

The body of a class or function declaration contains a series of statements or declarations separated by ";". The semicolon means "and". In an imperative language the order is important ( A; B is not equivalent to B; A) so this fact is obscured. By identifying variables in an imperative language as "roles" the meaning of ";" becomes clear.

Functions
The traditional view of a call to a function is that it is a representation of the value returned by the function. This is the view implicit in the C++ style of declarations.

An alternative view is is that a function call represents an object, that is then executed to give the result. The "@" symbol in front of the function call represents this intermediate object. The "^" symbol represents the execution of the call.


 * x : long = fact(5);
 * y : (long n) -> long = @fact(5);
 * z : long = y^;

This mechanism allows a function call to be created, and stored for later execution.

The result of a function needs to be represented in the function body. The Pascal way in ungainly because it makes it harder to change the name of the function. The C++ approach is hard to represent in logic, because it violates the flow of control by immediately exiting the function. The reserved word "result" is introduced to represent the return value of the function.

There is another implicit return value in a statement. A statement implicitly returns a boolean value. So,


 * Dog.GoodDog: -> bool
 * Clean;
 * WellBehaved;
 * GoodLooking;
 * }
 * }

should mean that the function result is obtained by anding together the results of calling the functions Clean, WellBehaved and GoodLooking. So the default behaviour of a function should be return the value of an expression,


 * Multiply : (a: long, b: long) -> long
 * a * b
 * }
 * }

This is a nice clean syntax but it makes it harder to introduce conditions into the evaluation. So if the result keyword is used, the expression must be a boolean condition, and result is the value. For example in,


 * Fact : (n: long) -> long
 * if n = 0 then
 * result = 1
 * else
 * result = n * Fact(n-1)
 * }
 * }

The body is a boolean expression, but result represents the value returned by the function call.

Features to be removed
The following features go against the natural representation of a program as logic,


 * return
 * continue
 * break
 * goto
 * pointers

These features have no place in a logic based language.