bool(false)

Recent academy graduate Ralph shared his learnings about programming languages, how they differ, and why so many exist…

Since starting at the academy I’ve immersed myself in the world of software development. During my time on the course I started to hear references to programming languages other than PHP – which the course is focussed on. In this blog, I want to share what I’ve learnt about which aspects are unique to PHP and which are common to other languages, to help myself and others better understand what a programming language is, how languages differ from each other, and why there are so many.

So what is a programming language and how does it communicate with a computer?
A programming language is a means of giving instructions to a piece of hardware. It consists of a set of keywords and symbols, and a syntax which must be followed when using them – similar to the vocabulary and grammar of spoken languages.

In modern computers, instructions are given through a chain of translations from one language to another. Although this chain can take various forms, typically it starts with source code written in a high-level language by the programmer, which is compiled into object code in an assembly language. This is then assembled into binary, which consists purely of ones and zeros that can be interpreted by a computer. These ones and zeros represent switches in the hardware, so the computer knows which should be on and which should be off.

Early computer programs only existed in machine language, but as programs became more complex and challenging to write, other languages started to emerge, to make code more accessible and faster to write. Today, when people talk about programming languages, they are generally referring to high level languages like PHP, C, Java and Python.

What are some differences between high level languages? Why use one over another?
There’s a very handy website called rosettacode.org – a nod to the Rosetta Stone which is famed for helping historians decipher ancient languages. The site contains a multitude of small programs, presented in code form in as many programming languages as contributors can amass. If the name is anything to go by, I thought, this will help me to gain some insight into the distinctions and similarities between languages.

The first thing I noticed when looking through the code is that the lengths of the scripts differ massively between languages for a given program. For example the ‘A + B’ program, which just sums two integers in the J language was simply ‘2 + 3’, whereas in SPARK it took slightly over 30 lines of code! This told me that it’s important to pick the right language for the job at hand.

After looking at various other programs, I found that the language list at the top of the page fluctuated hugely depending on the program, implying that some things are unfeasible in certain languages. I ought to mention that I found that the ‘A + B’ program mentioned above included an entry for a language called Sed, along with the text, “Sed is for string processing and has no facility for manipulating numbers as numeric values.” The fact that someone went to the length of forcing Sed to sum two numbers tells us that if a language isn’t listed, it’s near impossible to perform the given task using that language.

What are verbose and terse languages?
While I could get the gist of some of the scripts at a glance, I found many difficult to penetrate, even when I knew what they were supposed to do. After picking through various forum threads and articles, I discovered that what I was encountering was the concept of verbosity or expressiveness. If a language is ‘verbose’ then its appearance is descriptive of what the code is doing – making it more accessible to the unacquainted. In other words, the more verbose a programming language is, the more it resembles a human language. This is governed primarily by the language’s keywords, built-in function names, syntax and general naming conventions. This is a relative term, with less verbose languages being referred to as ‘terse’.

Verbosity does not necessarily imply readability, and this is hotly debated in the forums. Some favour terse languages, saying that they are neat and concise and that verbose language adds unnecessary ‘noise’ to the code. Others claim that terse languages are harder to follow as there is little signposting of what’s going on.

What have I learned about the key differences between languages?
The academy students attended a course on implementing the Zend Framework – taught by esteemed software engineer Rob Allen. This gave me further insight into the distinctions between languages. Rob explained that unlike many other languages, PHP deletes anything being stored at the end of a script run. Hence PHP starts from scratch each time it runs a script, and so is optimized for a quick start-up time. It also means that writing destructors to close resource handles, and deleting variables to free up memory doesn’t feature as heavily in PHP code as it does in languages with longer run times. So I am starting to see that languages not only differ in how the components are built up to make statements, but also in how frequently different sorts of statements appear in the code.

Although I’ve only scratched the surface, I now have a better view of the nuances of programming languages. It seems to me that the reasons for using a particular language can be split into two categories, roughly speaking. The first is appropriateness to the task and the second is personal taste.

For the first I would like to use the analogy of tools in a toolbox:

  • for some tasks different tools are equally adequate and it comes down to the user’s priorities: hammer or nail gun?
  • in other tasks, although two different tools would do, one is clearly better for the job: pliers or spanner?
  • and sometimes a certain tool just isn’t an option: try drilling a hole with a plane!

In the future I plan to further my learning by looking into the differences between procedural, function and object-orientated programming, how languages evolve over time and their resulting family structures, and how one would go about writing a new language.

I’ll leave you with a great interactive map to explore links between languages.