What is …
A computer program?
- A computer program is a sequence of instructions written using a Computer Programming Language to perform a specified task by the computer.
- It’s a little bit like map directions or a food recipe.
- Also called software, app.
- Programs can range from two lines of instructions to millions of lines.
- This is the process of designing and writing computer programs.
- Also called ‘coding’.
Computer Programming Language?
- A language is a set of rules, principles, and processes (including vocabulary and grammar) for instructing a computer to perform specific tasks.
- Hundreds of computer programming languages have been developed.
- There are certain basic program code elements that are common for all the programming languages.
An algorithm is a self-contained, step-by-step set of operations that performs a particular task or solve a specific problem.
Basic types of algorithms include:
- searching, or looking for an item in a list.
- sorting, or putting a list in alphabetic or numeric order.
- shortest path, or finding the quickest way on a map from point A to point B.
- compression, or reducing the size of a data file.
Algorithms resemble recipes in so much as recipes describe how to accomplish a task by performing a number of steps, such as baking a cake by: preheating the oven; mixing flour, sugar, and eggs; pouring into a baking pan; putting in oven; baking until done; etc.
However, ‘algorithm’ is a technical term with a more specific meaning than ‘recipe’. It expects a defined set of inputs and outputs, and is guaranteed to end and produce a result, always stopping after a finite time.
Why are algorithms important in programming?
Algorithms are the building blocks of computer programs.
Any programming is a two step process:
- deciding how to solve the problem, and
- writing it as code.
Choosing or designing an algorithm is a fundamental part of the first step.
An Example Algorithm: find_max()
In the programming language Python, this would look like:
Basic elements of coding
Many elements of coding are common to all computer programming languages. These include:
- Programming Environment
- Data Types
- If else conditions
Although not an element of a computer programming language, the ‘environment’ is the first step to be followed before writing any computer code. It’s simply the platform on top of which programming can take place.
To code using any programming language, you will need the following setup to start:
- A text editor to create computer programs.
- A compiler to compile the programs into binary format.
- An interpreter to execute the programs directly.
A text editor is a software that’s used to write computer programs, like:
Notepad (which comes free on all Windows computers)
Open Notepad under ‘Windows Accessories’ (via Start Button/Windows Icon bottom left of screen)
Alternative text editors include:
TextEdit (if you are a Mac user)
Compilers and interpreters
You write your computer program using a programming language and save it in a text file called the program file. However, a computer cannot read this directly and needs help, either from a Compiler or Interpreter
A computer ‘think’s in binary, 1s and 0s, so cannot understand your program directly as it’s written in text format. Therefore, we need to convert the text formatted program to a binary format file, which can be understood by the computer. This conversion is done by software called a Compiler and the process of conversion is called program compilation. Finally, you can execute binary file to perform the programmed task.
Some programming languages – such as Python, PHP, and Perl – do not need any compilation into binary format. Instead an interpreter can be used to read such programs line by line and execute them directly without any further conversion.
NEXT TIME: Basic Syntax
Watch this video and complete the