StateWORKS

Modeling Software with Finite State Machines: A Practical Approach

Below you can read a chapter from our book "Modeling Software with Finite State Machines: A Practical Approach". Click here to go back to the book promotion pages.

Programming languages

Software is inherently linked with programming languages. For people outside the software industry the two are the same.

A programming language is a formal language defined by its syntax and semantics. The programming language is used to write programs which are carried out by computers. There are hundreds, maybe thousands of programming languages, most of them irrelevant. The overwhelmingly majority of programs are written in a few dominant programming languages.

A little history

Programming began with writing programs into a computer memory in a form of octal or hexadecimal numbers which represented the binary-coded program instructions (machine code). For example 0272 12601 is an indexed indirect jump for one old computer, and some programmers were happy to work with such coding. Soon the numbers were replaced by instruction names - the assembler was born. Assembler notations, just like the underlying binary code, are closely linked with the processors. So, each processor has its own assembler language. There were some efforts made to introduce a common assembler notation , as for instance CALM , which would have broken the bindings between the processor and the assembler. Those efforts failed and resulted only in some short-lived and locally limited implementations.

That direct fiddling with bits and bytes while programming was very time consuming though the programs themselves were effective. In the sixties the first general programming languages appeared which were application oriented - the direct link between a processor and a program has been removed. A given program could have been carried out on any computer. To realize it, translation programs (essentially a compiler and a linker) were used which converted the program into processor specific instructions. The most important early programming languages were Fortran and COBOL which were not grounded on any solid design philosophy because the theoretical basis of the emerging software practice was rather thin in those days (we should not forget that only 40 years ago relatively obvious but important observations were being published; for instance that overuse of the goto statement leads to disastrous code ). Attempts to introduce languages based on some theoretical presumptions like Algol or later Ada failed to have wide impact, maybe on account of the design-by-committee problem, although a certain number of valuable concepts were established.

The lessons of the use of the early and intuitively defined languages led quickly to the idea of structured analysis and design. The best realisation of that idea was Pascal which was the programming language in the seventies / eighties. For reasons which, from a technical point of view, are hard to understand Pascal was replaced by C, and Modula 2 was ignored. The effect of the C language could be described by a remark "hearing about a major software catastrophe I can be sure that it has been written in C". Anyway, that language, with its descendant C++, seems at the time of writing to have won the battle for supremacy.

BASIC catastrophe

Speaking about software catastrophes we should mention BASIC. There are not known large software catastrophes linked with BASIC as nobody has tried to write large program with it but in its way it is a disaster, when considering its bad influence on programming style. BASIC was introduced as a teaching language for students of programming, or perhaps we should say coding, with an apparent advantage of interactivity, as when first introduced in the 60's it was interpreted rather than being compiled. This encouraged users to just start coding, and to fight their way through a mass of errors and misunderstandings until they seemed to have a successful program. BASIC was never a favourite language for experienced programmers. Dijsktra pointed out once that a person who was taught programming using BASIC would never be a good programmer. The statement should not be interpreted directly (we are taught many stupidities in our youth but as adults most of us manage to overcome the ballast) but it describes well the serious programmers' opinion of BASIC. That language encountered an astonishing evolution, taking over several proven ideas from object oriented languages and a modern version, Microsoft Visual Basic, stays popular. In fact, many millions of useful small-scale projects have been implemented with Visual Basic, which provides superb facilities for a certain class of software running in the limited environment of the Windows desktop. In spite of that, a C++ programmer cannot understand why he should ever use BASIC when he can do the same things in C++ better and more elegantly. Visual BASIC has some serious limitations which come into being if we want to do something serious. We are enthusiastic if creating nice pictures on the screen but leaving the graphics behind we fall flat on our face very soon.

C++

We have already mentioned C++ which is the language of the last decade. It is the flag ship of the idea of object oriented programming which evolved in the late eighties. That paradigm was the last great step in the direction of better programming languages. The success of C++ is also difficult to explain; probably its evolution from the very popular C played here the decisive role. There are languages which implement better the idea of object oriented paradigm especially Smalltalk where a programmer lives truly in an object world. This is in contrast to C++ where a programmer is still confronted with the plagues of the C language, like pointers, global variables and functions, garbage collection, exception handling etc. There are of course several other object oriented languages, the most interesting being Java or C#. The variety of languages fulfils the goal of having some advantages over other languages from certain point of view, in a certain environment but we cannot say that any of the languages are in principle better than others. As we pointed also above the dominance of C++ does not mean that it is the "best" programming language seen from some theoretical viewpoint. Languages defined on a sound theoretical basis have never gained wide acceptance (see the already mentioned Algol or Ada).

PLC

Speaking about programming languages we should not forget PLC (Programmable Logic Controller) programming methods. The way PLCs are programmed has never excited programmers, especially the true PLC programming in form of ladder diagrams or function plans. Anyway PLC programming is successful and often used. The tight links between the PLC hardware and programming have not allowed any other way of doing it which explains the success story.

The PLC world is very separate world. It is so isolated from the main stream of software development that some programmers do not consider it as true programming. The separation has stemmed from the close linkage to the hardware, i.e. to the Programmable Logic Controllers and the relay logic which preceded them. The application domain for the PLC is well defined and limited to industrial control, where first of all the hardware is needed as a data acquisition system which is the interface between the controlled production system and the computer. For several years PLC hardware used its own execution units and for that proprietary hardware each company developed its own software development environment. After the proprietary computing systems had been replaced by open hardware solutions symbolized by PC the PLC world delayed any changes favoured by the marketing situation in that field: a few big companies shared and controlled the market. Eventually they were forced to open the PLC to non-proprietary solutions - standards for programming languages having been introduced (for instance IEC 61131-3). Those standards are taken seriously in Europe, although the US companies are delaying the acceptance, still stuck on ladder diagrams which differ slightly from one manufacturer to another one. Standards in turn have allowed the use of the PC as a control unit.

From a technical point of view PLC programming methods (ladder diagram, structured text, function block diagram, instruction list and sequential function chart) do not have any advantages over other programming languages, but the nature of a PLC language is such that the developer is able to concentrate on the application, rather than having to spend half his time struggling to avoid or to correct programming-syntax problems. The main sense of this approach is the large potential represented by people who know the industrial control problems and can program in PLC languages and the good development tools provided by PLC manufacturers. The power of PLC manufacturers plays here too a decisive role. It is rather difficult to convince for instance a C, C++ or Java programmer to change voluntarily to PLC, but many firms have, nevertheless, chosen to adopt them after having suffered with conventional programming in the days of the mini-computer, in the same way that some firms chose Visual BASIC rather than C or C++, so as to concentrate better on the application and have fewer obscure bugs in the final product. We present detailed criticisms of the IEC 61131-3 methods in Appendix E Going beyond the limitations of IEC 61131-3.


Script or Macro notations

A very special type of programming language is script languages called also command or macro languages. In principle, for any job we may invent a special language. If we can, we do it. So, of course any operating system has its script language: the IBM mainframe JCL, DOS "bat" (very poor), UNIX shell programming, quite good but unfortunately every UNIX variant has a slightly different one. Many application programs have one - called a macro language: editors (WordPerfect, Word, OpenOffice, ...), data bases (Access, MySQL, ...), Spreadsheets (Excel, QuatroPro, ...), Internet applications (Browsers, ...). We had better stop the list - effectively it could contain all application programs. There were attempts to introduce BASIC as a common macro language at least for MS Windows applications, with little success.

There is a hope that eventually XML notation will become a lingua franca of the computer world. Interestingly, XML is not a programming language but just a data description language and it can be used only with some execution environment which gives the data the true interpretation. Anyway, it seems that it could solve the Tower of Babel mess existing in script, command and macro languages.

There are many languages

In such a way we reach the end of this short history of programming languages. If a reader programs at the moment for instance in Prolog or Lisp he could ask why his programming language has been omitted. There are several languages whose only reason for existence is that they have been developed for a very specific application domain and outside that domain they are just useless. The list of such specific applications and corresponding languages is long. For instance many years ago I have tried to program in APL and I was enthusiastic about the compactness of the language - for some mathematical exercises it was a perfect tool. But it was also obvious that that language is just a toy that will never reach any importance.

As a final comment, we suggest that most programming languages do not "scale" very well. They are easy to use for writing small and self-contained programs, but for real-life and very complex projects the control structures are such as to make the final code almost impossible to comprehend in its entirety.