Skip to content

Computer Science · Ch 4 — Introduction to Problem Solving

Coding

4.8

Coding

Once an algorithm is finalised, it must be coded in a high-level programming language of the programmer's choosing: the ordered set of instructions is written in that language, following its syntax. Syntax is the set of rules — the grammar — that governs how statements of the language are formed: spellings, order of words, punctuation and so on. Just as a sentence with broken grammar confuses a reader, a statement that violates the language's syntax cannot be processed.

Machine language versus high-level languages

  • Machine language (low level language) consists of 0s and 1s only. From the computer's viewpoint it is the ideal way to write a program: instructions in binary are directly understood by the computer hardware. For humans, however, programs written in binary digits are difficult to work with and comprehend.
  • This difficulty led to the invention of high-level languages, which are close to natural languages and far easier to read, write and maintain — but which the computer hardware cannot understand directly.
  • Portability is a further advantage of high-level languages: a high-level program can run on different types of computers with little or no modification. A low-level program, by contrast, runs on only one kind of computer and has to be rewritten to run on another type of system.

A wide variety of high-level languages exists — FORTRAN, C, C++, Java, Python, and others.

Source code and translation

A program written in a high-level language is called source code. Since the hardware cannot execute source code directly, it must be translated into machine language using a compiler or an interpreter (both were introduced in Chapter 1). Only after translation can the computer understand and run the program.

Choosing a programming language

With many languages available, choosing the right one for a task depends on several factors:

  • The platform (operating system) where the program will run.
  • The kind of application:
    • Desktop applications and mobile applications are generally developed for a particular operating system and for certain hardware.
    • Web applications are accessed on many different devices through web browsers, and may use resources available over the cloud. …