The ABC Programmer's Handbook by Leo Geurts, Lambert Meertens, and Steven Pemberton

Preface

Why ABC?

The answer to the question 'Why a new language?' is the same as the answer to the question 'Why new computers?': because they can help you do the job better. With the choice between a language where it will take a week to write a program, and a language where it will take an afternoon, most people will choose the latter.

ABC is a powerful, easy-to-learn and easy-to-use interactive programming language, intended for personal computing and designed as a modern alternative to BASIC and an easy alternative to Pascal. It supports data structuring and structured programming. As it turns out, ABC is even easier to learn and use than BASIC, and a more powerful tool than Pascal.

ABC is not simply a language, it is a language embedded in a dedicated system. Programming in ABC has a strongly interactive feel. Rather than writing one long program, one develops a set of commands, functions and data that are kept by the system until they are intentionally deleted.

ABC is the result of several years' research towards a language that is simple to learn but easy to use. It was started as an attempt to produce a reasonable replacement for BASIC, with as initial aims that it should be

ABC is the fourth iteration in this development and reflects several important ideas:

We started off designing a language for beginners, but the resulting language has become a pleasure to use for both beginners and 'experts' alike.

Application Area

ABC doesn't offer any new programming 'paradigm' or method of programming: it is an algorithmic language (like BASIC, Pascal, or C) intended for personal computing. You use it for the sort of programming that BASIC or Pascal would normally be used for: general everyday programming. ABC is not a systems-programming language, though it is an excellent vehicle for expressing and developing systems-programming type algorithms.

Major Points

The advantages of ABC can only really be appreciated by looking at example programs, or better still by writing them. In fact, simply listing the features of the language is just as likely to elicit the response 'so what?'. However, the following are a number of the principal properties of ABC.

Simple

ABC is very simple to learn. For example, whereas Pascal has 13 data types, and C has 19, ABC has only 5. However, this simplicity is not at the expense of expressibility: the data types have been chosen very carefully to allow data structures like sets, trees, dictionaries, and so on, to be easily defined.

ABC is also simple to use. Because of the high-level tools supplied in the language, powerful programs are easy to write and manage.

Compact

ABC programs are typically 4 or 5 times shorter than the equivalent Pascal or C program. However, this is not at the expense of readability by using unfamiliar hieroglyphics. In fact, the shortness makes programs clearer.

ABC can be likened to the 'pseudo-code' that is used when designing a program, except that ABC code is executable.

Structured

ABC has the usual flow of control commands, like IF, WHILE and so on, means for defining your own commands and functions, and even a way of expressing program refinements, to support top-down programming (there is no GO TO). Data structures are also structured.

Expressive

ABC is problem-oriented, so you can express your problems at the level that you conceive them. It also allows you to create your own data structures, commands and functions, and so extend the language to your own needs.

Unified

Many concepts in other languages have been unified in ABC. For instance, the division between 'variables' and 'files' in other languages reflects that computers have a two-level store: main store and disk. In a traditional language, if you want to save a data structure between runs of a program, you have to explicitly convert the data structure to textual form and write it to a file, and read it back and reconstruct the structure the next time. ABC doesn't distinguish between levels of store. Global locations (variables) are kept between sessions, so you don't have to explicitly save them yourself. This approach has the advantage that the language is kept small -­there is no need for special file-handling commands­- and it gives the user much more power, since the operations available on data-types are at a much higher level than the file-handling facilities in most other languages.

Other languages distinguish between (built-in) commands (or statements) of the language, user-defined procedures, and programs. ABC just has commands. Some are built in, the user can define new ones, and a command is just the same as a program. This of course also simplifies passing parameters to a program: if it is possible at all in other languages, it is usually done using a completely different mechanism than that for passing parameters to a procedure. Since ABC doesn't distinguish between program and command, you use the same mechanism for both.

High-level

Traditional programming languages supply low-level facilities that can be used to build high-level tools. ABC works the other way round: you get high-level tools that you can also use for low-level purposes. For example:

Obvious

The language has been designed to be unsurprising for the new programmer. For instance, there are no size limits built into the language. Numbers may be as long as you want, as may texts (strings), all this without having to give a maximum size in advance.

The behaviour of the language is consistent. You may return any value, and any type of value, from a function. You may store any type of value in a location. A program may write out any type of value.

Interactive

Any command you type directly to ABC gets executed immediately. All values are visible: you can always write them out to see what's in them.

Even though there are no declarations, there is type checking, by ensuring that locations are used consistently. This gives you the added security that declarations would normally give you, without you having to provide them.

Ease of typing is given not by using very short keywords, but through the system giving suggestions and command completion. Indentation is used to group commands, so no BEGIN-END structure is necessary.

ABC is a programming language and environment. This environment shows one face to the user: the command language is ABC, so you don't have to learn another language in order to manage the system. The system knows about the structure of ABC and so supplies suggestions, indentation, matching brackets and so on automatically. You are always in the editor, so you can edit immediate commands and program input in exactly the same way that you edit commands and functions.

Experience

As mentioned before, ABC is the result of several years' development, so that we have had ample time to evaluate and tune the language.

The language is now in use in schools, universities, research institutes and companies around the world, and we are extremely satisfied with and enthusiastic about the results. Many people use ABC as their primary programming language.

The implementation of ABC is an interpreter, which means of course that programs run slower than the equivalent program written in a compiled language. On the other hand, it takes much less time to write a program, which must be taken into account. But even if a given program must run as fast as possible, ABC is still a good choice for developing the algorithms for the program, and prototyping the program.

About this Book

This book is an introduction to ABC and its implementations, for people who have already programmed.

It consists of first a quick introduction, giving a brief and informal overview of the whole language. This is followed by a chapter of example programs. These examples demonstrate ABC style, and how you program some common data structures in the language. After that is a user's guide to using the ABC implementations, explaining how to use the ABC system, how to manage ABC programs, and so on. Finally, there is the Description of ABC, a semi-formal definition of the language, giving the syntax and semantics of the language, and the definition of the built-in commands and functions.

If you are sitting at a computer terminal or PC reading this and trying ABC at the same time, you should read the chapter on using ABC first.

There are two things that this book isn't. Firstly, a beginner's introduction to programming in general: a beginner has completely different needs than can be supplied in a book like this. Secondly, it isn't a justification or rationale of why ABC is like it is. There are so many reasons for each detail of ABC, that this book would be swamped with detail.

Implementations

There are implementations of ABC available for several platforms.

They are available at http://www.cwi.nl/~steven/abc. For the Unix version you get the sources to the system, for the other versions you get a binary. They are not 'public-domain': they are copyrighted, but free. This means that you may give them to, or get them from, your friends.

You may also contact us by electronic mail at:

abc@cwi.nl

For more information about ABC, such as example programs, discussions of techniques, and news about new publications and other developments, see the website mentioned above.

Acknowledgments

Many people have been involved over the years with our group and the development of the language. Principally should be mentioned Frank van Dijk, Timo Krijnen, Guido van Rossum and Eddy Boeve, who wrote large parts of the implementations, and put a lot of personal effort into making ABC what it is.

The ABC Programmer's Handbook by Leo Geurts, Lambert Meertens, and Steven Pemberton