Evolution of the COBOL Language at Micro Focus Since 1985

The ANS85 Standard

The COBOL programming language has a famously long history, dating back to the early 1960s and the days of Admiral Grace Hopper. It came of age though with the publication of the ANS85 COBOL standard. By that time, COBOL had developed a huge following and was already running a vast number of businesses all over the world. However, ANS85 COBOL was the first "modern" version of COBOL, allowing for proper structuring of code, using scope delimiters such as END IF rather than relying on the infamous period/full stop to terminate all statements. It was also the first version of COBOL to provide proper looping constructs using in-line PERFORM statements, which meant that there was no longer a need for the widespread use of GO TO statements. Minor incompatibilities caused some controversy at the time, and the strength of the reaction (including threats to sue the standards body) showed just how important COBOL was seen to be.

Object-oriented (OO) programming and ISO2002 standard

Around the time the ANS85 standard was published, the programming world started getting interested in the idea of object-oriented programming, graphical interfaces and so on. Much of this interest was stimulated by work at Xerox Parc, which developed the Smalltalk language along with the first windowing software. Smalltalk was a ‘pure’ object-oriented language, in which everything was an object, including primitive integers, etc. On the other hand, C++ and Objective C were hybrid languages, aiming to graft object-oriented concepts onto the existing C language.

The COBOL world was quick to follow and by 1987, the COBOL standards committee of ISO had set up a working group to investigate the incorporation of OO ideas into the COBOL language. At the same time, Micro Focus was working on OO prototypes partly based on the work of the standards group, and partly feeding into that group. The proposed OO syntax went through many iterations, with input from people with a Smalltalk perspective, as well as from the world of C++/Objective C. The end result retained many of the aspects of Smalltalk, including the idea of a class or factory object, which is a notional object representing the class itself (rather than instances of the class). Methods on the class object correspond more or less to static methods in other implementations.

The new standard was eventually published in 2002, but did not have the success of the 1985 standard. To date, no vendor has implemented the complete standard, and in fact significant parts of it have been made optional in later versions. Micro Focus did produce a full implementation of the OO aspects of the standard, and it met with some success with our users, and served as the basis for later implementations of our Dialog System GUI design tool.

.NET COBOL syntax extensions

Shortly before the publication of the 2002 standard, Micro Focus started thinking about the new .NET platform that had been developed by Microsoft, in association with many other software vendors, and published as a standard by ECMA - see Related Information.

IL, intermediate and generated code

At the heart of .NET is an abstract machine, generally referred to as Intermediate Language (IL), and the central idea is that compilers for different languages can all convert code written in ‘their’ language into the same IL. Micro Focus was very familiar with the idea of abstract machines, having developed its own COBOL abstract machine in the late 1970s. Originally, the Micro Focus Compiler (then known as CIS COBOL or Compact Intermediate Standard COBOL) converted COBOL into a sequence of abstract machine instructions, which were then interpreted at run time by our run-time system. A little later, Micro Focus created code generators for the major CPUs at the time, which converted this abstract machine directly into real machine code, and which therefore ran much faster than the interpreted code.

Just-in-time compilation

The .NET IL, and the Java Virtual Machine which preceded it, was a little different in that it was designed for ‘just-in-time’ compilation (‘JIT’). Instead of being interpreted, or compiled to a specific instruction set, the idea behind JIT is to load the abstract machine code at run time, and to convert it on the fly to the actual instruction set in use by the CPU. This meant that the same code could be run on very different chipsets (e.g., 32-bit and 64 bit), and that the code could be optimized to suit the environment in which it found itself running.

When Micro Focus first started working on a compiler that would target the .NET Framework, the focus was very much on traditional ‘procedural’ COBOL. What this meant in practice is that we created from the COBOL a class, with the contents of working-storage being the instance data for that class, and the procedure division being an instance method. Extra methods were produced for any ENTRY statements that might be present in the procedure division.

.NET COBOL Syntax

When the question arose of what we should do about OO COBOL, it was clear that not all aspects of ISO 2002 COBOL could be implemented. .NET IL is very generic, in that it is not tied to a particular computer language, but on the other hand it does incorporate its own very specific view of what the object-oriented world looks like. Thus, multiple inheritance is not implemented in .NET, and is therefore not implemented in the .NET version of object-oriented COBOL. Class objects are replaced by the simpler idea of static methods, fields etc. On the other hand, the ISO 2002 syntax was not adequate to allow COBOL programmers to integrate fully and easily into the .NET platform.

The full list of extra syntax is very long, but includes things like value types, delegates, enumerations (or enums), iterator methods, operator overloading, and single and multidimensional arrays whose size is determined at run time.

It was also found that the ISO2002 syntax was wordier and more convoluted than necessary. To give an idea of some of the simplifications that Micro Focus introduced into the language, the following are two short examples of manipulating a .NET string object, the first using ISO2002 syntax, and the second using Micro Focus syntax extensions.

ISO2002 syntax:

       repository.
           class sys-string as "System.String"
           property len as "Length".
       01 s1 object reference sys-string.
           set s1 to "Hello world"
           display len of s1

In ISO2002 syntax, any reference to an external class or property (such as the class System.String or its property Length) has first to be associated with a COBOL name in a so-called REPOSITORY section, and then referred to via this COBOL name.

Micro Focus syntax:

       01 s1 type System.String.
           set s1 to "Hello world"
           display s1::Length

In the Micro Focus (MF) syntax, classes (and other types such as interfaces and delegates) can be referred to directly using the type keyword. Properties (and other members of classes such as methods, fields and events) can be referred to directly using the :: operator.

Whereas the statement "display len of s1" is fairly opaque, requiring the reader to go and find the definition of "len" in the repository, the statement "display s1::Length" is explicit and intuitive.

JVM COBOL

The first version of COBOL for .NET was released as part of the Micro Focus Net Express product in 2003. Shortly afterwards, we began to consider whether we could do the same for the Java world’s Java Virtual Machine as we had for .NET. This eventually resulted in the first release of COBOL for JVM in 2010, as part of the Visual COBOL product. The aim with the JVM product was to allow as much portability as possible between it and the .NET product, and this required implementation of some features that are not a standard part of Java. Examples include iterator methods, delegates, operator overloading and extension methods. As part of this drive for portability, we also introduced standard names for common types like strings and collections. So, one can now declare:

  • 01 s1 string. - declaration of a simple string object
  • 01 dict1 list[string]. - declaration of a list, whose elements are all strings.

where string and list are predefined types, corresponding to System.String and System.Collections.Generic.IList in .NET, and to java.lang.String and java.util.List in JVM.

Much of Micro Focus's internal software, used to support the Visual Studio and Eclipse IDEs, is now written in this portable OO syntax, which can therefore be compiled to .NET for use in the Visual Studio environment, or to JVM for use with Eclipse.