Sather
Encyclopedia
Sather is an object-oriented programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

. It originated circa 1990 at the International Computer Science Institute at the University of California, Berkeley
University of California, Berkeley
The University of California, Berkeley , is a teaching and research university established in 1868 and located in Berkeley, California, USA...

, developed by an international team led by Steve Omohundro
Steve Omohundro
Steve Omohundro is an American scientist known for his research on Hamiltonian physics, dynamical systems, programming languages, machine learning, machine vision, and the social implications of artificial intelligence...

. It supports garbage collection
Garbage collection (computer science)
In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program...

 and generics
Generic programming
In a broad definition, generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters...

 by subtypes.

Originally, it was based on Eiffel
Eiffel (programming language)
Eiffel is an ISO-standardized, object-oriented programming language designed by Bertrand Meyer and Eiffel Software. The design of the language is closely connected with the Eiffel programming method...

, but it has diverged, and now includes several functional programming
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...

 features. It is probably best to view it as an object-oriented
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...

 language, with many ideas borrowed from Eiffel.

Even the name is inspired by Eiffel; the Sather Tower
Sather Tower
Sather Tower is a campanile on the University of California, Berkeley campus. It is more commonly known as The Campanile due to its resemblance to the Campanile di San Marco in Venice, and serves as UC Berkeley's most recognizable symbol. It was completed in 1914 and first opened to the public in...

 is a recognizable landmark at Berkeley, named after Peder Sather
Peder Sather
Peder Sather was a prominent Norwegian-born American banker who is best known for his legacy to the University of California, Berkeley. His widow, Jane K. Sather, donated money in his memory for two of the school's most famous landmarks...

 who donated large sums to the foundation of the university.

Sather also takes inspiration from other programming languages and paradigms: iterator
Iterator
In computer programming, an iterator is an object that enables a programmer to traverse a container. Various types of iterators are often provided via a container's interface...

s, design by contract
Design by contract
Design by contract , also known as programming by contract and design-by-contract programming, is an approach to designing computer software...

, abstract classes, multiple inheritance
Multiple inheritance
Multiple inheritance is a feature of some object-oriented computer programming languages in which a class can inherit behaviors and features from more than one superclass....

, anonymous function
Anonymous function
In programming language theory, an anonymous function is a function defined, and possibly called, without being bound to an identifier. Anonymous functions are convenient to pass as an argument to a higher-order function and are ubiquitous in languages with first-class functions such as Haskell...

s, operator overloading
Operator overloading
In object oriented computer programming, operator overloading—less commonly known as operator ad-hoc polymorphism—is a specific case of polymorphism, where different operators have different implementations depending on their arguments...

, contravariant
Covariance and contravariance (computer science)
Within the type system of a programming language, covariance and contravariance refers to the ordering of types from narrower to wider and their interchangeability or equivalence in certain situations ....

 type system. Some of these features are normally only found in functional programming languages.

The original Berkeley implementation is now maintained by many people, not all at Berkeley, and has been adopted by the Free Software Foundation
Free Software Foundation
The Free Software Foundation is a non-profit corporation founded by Richard Stallman on 4 October 1985 to support the free software movement, a copyleft-based movement which aims to promote the universal freedom to create, distribute and modify computer software...

 therefore becoming GNU Sather. There are at least two other implementations: Sather-K from the University of Karlsruhe, and Sather-W from the University of Waikato
University of Waikato
The University of Waikato is located in Hamilton and Tauranga, New Zealand, and was established in 1964. It has strengths across a broad range of subject areas, particularly its degrees in Computer Science and in Management...

.

The former ICSI sather compiler (now GNU Sather) is implemented as a compiler to C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

, i.e., the compiler does not output object
Object file
An object file is a file containing relocatable format machine code that is usually not directly executable. Object files are produced by an assembler, compiler, or other language translator, and used as input to the linker....

 or machine code, but takes Sather source code
Source code
In computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...

 and generates C source code as an intermediate language
Intermediate language
In computer science, an intermediate language is the language of an abstract machine designed to aid in the analysis of computer programs. The term comes from their use in compilers, where a compiler first translates the source code of a program into a form more suitable for code-improving...

. Optimizing is by the C compiler, Sather code often performs better than the corresponding C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

 code, and the generated C code can always be optimized by hand.

The GNU Sather compiler, written in Sather itself, is dual licensed under the GNU GPL
GNU General Public License
The GNU General Public License is the most widely used free software license, originally written by Richard Stallman for the GNU Project....

 & LGPL.

Hello World

class HELLO_WORLD is
main is
#OUT+"Hello World\n";
end;
end;

A few remarks:
  • Class names are ALL CAPS; this is not only a convention but is enforced by the compiler.
  • The method called main is the entry point for execution. It may belong to any class, but if this is different from MAIN, it must be specified as a compiler option.
  • # is the constructor symbol, calling method create of the corresponding class; here it is used for instantiating the OUT class, which is actually stdout.
  • The + operator has been overloaded here to stand for stream append.
  • Operators such as + are syntactic sugar
    Syntactic sugar
    Syntactic sugar is a computer science term that refers to syntax within a programming language that is designed to make things easier to read or to express....

    for conventionally named method calls: a + b stands for a.plus(b). The usual arithmetic precedence conventions are used to resolve the calling order of methods in complex formulae.
  • The program layout allows for pre- and post-conditions (not shown here), showing Sather's Eiffel lineage.

Example of iterators

class MAIN is
main is
loop
i := 1.upto!(10);
#OUT + i + "\n";
end;
end;
end;

This program prints numbers from 1 to 10.

The loop ... end construct is the preferred means of defining loops (although while and repeat-until are also available). Within the construct, one or more iterators may be used. Iterator names always end with an exclamation mark (this convention is enforced by the compiler). upto! is a method of the integer class INT accepting one once argument, meaning its value will not change as the iterator yields. upto! could be implemented in the INT class like this:

upto!(once m:INT):SAME is
i: INT := self; -- initialise i to the value of self,
-- that is the integer of which this method is called
loop
if i>m then
quit; -- leave the loop when i goes beyond m
end;
yield i; -- else use i as return value and stay in the loop
i := i + 1; -- and increment
end;
end;

Type information for variables is denoted by a postfix syntax variable:CLASS. The type can often be inferred and thus the typing information is optional, like in anInteger::=1. SAME is a convenience pseudo-class referring to the current class.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK