Languages

What to expect

Early programs were hard-coded with wires and switches, or programmed in binary.

The development of programming languages is the story of this chapter, including Grace Hopper’s “FLOW-MATIC” and “COBOL”, structured programming and the “GOTO heresy”, object-oriented code and a look at functional languages.

A quick preview of the chapter follows, this is my explanation of the different programming paradigms.

In the imperative paradigm, we write commands for the computer to perform, like imperative mood in English, where “come here” gives an instruction.
The focus is on control flow and programs consist of sequence, selection and iteration.
FORTRAN, ALGOL, Pascal, C++, Python and JavaScript are all imperative languages. A program in the declarative paradigm describes only the logic behind the computation, through functions or logic statements. Declarative languages come in several subtypes including the logical programming language Prolog, and functional languages  LISP, Scala and Haskell

TL;DR.

Early programming meant manually entering binary codes. Assembly language gave us mnemonics, but we still needed to understand the architecture. High-level languages FORTRAN, ALGOL and COBOL, abstract away the code from the architecture, letting us use English keywords IF, WHILE and FOR. A compiler translates this code into machine code, but we need one for every computer system, and because each high-level statement generates multiple machine code instructions, the object code might not be optimal.

Sequence, selection, iteration and subprograms are no accident, but a natural feature of algorithms, and are used in all imperative languages descended from ALGOL, including Pascal, C and Python. Structured code is preferred to “spaghetti code” because it’s readable and easy to maintain. C was written by the creator of Unix, and the “hackers’ language” evolved into C++ and C#, but has fussy syntax so is tricky to learn. Universities first taught using FORTRAN then Pascal but in 1981 UK schools went with BASIC as it was already popular on home computers. BASIC inspired Visual Basic, popular in the 1990s and still used today.

Object-oriented programming beginning with Simula and Smalltalk, gave us classes which are blueprints for objects, each object has attributes and methods and can interact with other objects. This programming style is useful for games programming but also modelling, simulation and AI applications. Java was the most popular language from around 2000-2015 because it was object-oriented and portable: it could run anywhere thanks to a Java virtual machine created for every popular platform.

Imperative languages like Java, C and Python execute a sequence of instructions. Another paradigm is declarative programming, which comes in two types: functional languages like LISP, Scala and Haskell, and logic languages like Prolog. A functional language describes merely how data is processed by functions. This often results in more elegant code with fewer bugs and is suited to scientific analysis and AI applications.

Code in an interpreted language is translated to machine code line by line, instead of compiled all at once. Perl, JavaScript and Python are all interpreted, allowing rapid coding and testing, which meets the demands of the modern software market. JavaScript is built into browsers to make web pages interactive. Python was designed in 1999 to be fun, simple and flexible. Its clean syntax made it a popular choice for teaching programming. According to Paul Dubois, co-creator of the NumPy library, Python is the “most powerful language you can still read”. šŸ”—

An understanding of this topic begins with the knowledge that at its heart a computer is just a collection of logic circuits which process digital signals of high and low voltages, representing zeros and ones. The circuits are able to decode certain patterns of zeros and ones and these bit patterns we call instructions. Each CPU responds to a finite set of these “low level instructions”: its machine code instruction set.

Coding in binary is difficult and error-prone, so each binary code is given a short, memorable name or mnemonic such as LDA, SUB or BRA. These mnemonics are called assembly language, as they were first used to assemble the binary codes needed to instruct the computer. Assembly language is still difficult to code and contains no useful constructs such as loops or arrays, so high-level languages were invented. High-level languages are more English-like and give us lots of features to allow us to write complex programs very quickly. Python, Java, JavaScript, VB.NET, C, C++ and C# are popular high-level languages. Assembly language may still be used where compact code is essential, or for small, mission-critical programs because the code it produces is extremely robust.

High-level code must be translated into machine code before it can be run on the CPU. For this we need a translator, and these come in two types: compiler and interpreter. Compilers translate the whole high-level source code program into machine code, creating an executable file of object code. Interpreters translate the program one line at a time, which allows for rapid coding and debugging but slower execution than compiled code.

Software containing lots of useful developer features called an Integrated Development Environment (IDE) is usually used to develop code. IDLE, PyCharm and Mu are popular IDEs for Python, Visual Studio supports C, C++, C#, VB.NET and JavaScript while developers might use Eclipse, NetBeans or IntelliJ IDEA for Java. An IDE provides many features to speed up coding such as syntax checking, autocomplete, stepping, breakpoints and variable tracing.

References

References from this chapter…

[81] TX-0 instruction set is here http://www.bitsavers.org/pdf/mit/tx-0/MIT_TX-0_InstructionSet.txt

[82] Dijkstra, CACM, March 1968.

[83] Knuth, “Structured programming with go to statements” 1979.

[84] Compilation stages on Isaac Computer Science

[85] See Isaac Computer Science for a tutorial on OOP.

Advertisements

[86] Haskell in Industry at the Haskell wiki: http://wiki.haskell.org/Haskell_in_industry

[87] “Why use Haskell” at the Haskell wiki: https://wiki.haskell.org/Introduction

[88] Paul Dubois quote from here https://morioh.com/p/11a20d9f2d0b

[89] App Lab at code.org https://code.org/educate/applab

[90] W3schools.com JavaScript tutorial https://www.w3schools.com/js/js_intro.asp

Advertisement