High-level Languages
Since programmers cannot realistically be expected to write programs in machine or assembly languages, they need a programming language that is easier for them to understand. This led to the evolution of several programming languages broadly referred to as high-level languages, which are easy for humans to write and read.
Large and complex programs are almost always written in a high-level language. They may not be as easy to understand as plain English, but they are a lot easier to understand than machine or assembly language, especially to a trained programmer. Some of the more popular high-level languages include C, C++, C#, Java, and JavaScript.
The description of a high-level programming language is usually split into "syntax" (form) and "semantics" (meaning).
-
Syntax is about the structure or the grammar of the language to be used to construct proper instruction. This is similar to human languages, which have grammar, or rules that define whether or not the sentence is properly constructed. But unlike in human languages where small grammatical errors are acceptable and the sentence may even be understood despite the errors, programming languages have zero tolerance for syntax errors and will not understand the instruction if even a single character is out of place.
-
Semantics is about the meaning of the instruction or what the processor is supposed to do. In some scenarios, the instruction may be correct in its syntax but wrong in semantics. For example, the syntax may allow an instruction that performs the addition of two numbers, but adding two letters has no meaning and is therefore semantically invalid.
Every language will have its own syntax and semantic rules, some are more forgiving than others.
Programming Styles
High-level languages are designed for two main programming styles which are explained below:
Imperative Programming
Imperative program involves providing commands that tell the computer exactly what task it should perform and how. It provides step-by-step instructions that the computer must follow as specified.
Within imperative programming there are two further styles:
- Procedural or Functional Programming
Procedural programming is a type of imperative programming in which the program is built from one or more procedures (also known as subroutines or functions). The use of procedures has a significant impact on how imperative programs are constructed. State changes are localized to procedures or restricted to explicit arguments and returns from procedures, resulting in a well-designed structured and modular program. This improves the size and maintainability of imperative programs.
Procedural programming could be considered a step toward declarative programming. A programmer can often tell, simply by looking at the names, arguments, and return types of procedures, what a particular procedure is supposed to do, without necessarily looking at the details of how it achieves its result. At the same time, a complete program is still imperative since it specifies the statements and procedures to be executed and their order of execution.
- Object-Oriented Programming
Object-oriented programming (OOP) is a programming paradigm based on the concept of objects, which can contain data in the form of fields (also known as attributes or properties), and code in the form of procedures (also known as methods or functions).
This approach has proven to be quite useful when modelling programs to solve real-world use cases by creating program objects that map to real objects in the domain for which the solution is being developed.
Many of the most widely used programming languages (such as C++, Java, and Python) are multi-paradigm and support object-oriented programming to a greater or lesser degree, typically in combination with procedural programming.
Declarative Programming
This style of programming focuses on specifying what the program should accomplish without specifying exactly how the program should achieve the result. The environment in which the program is executed takes its own decisions on how it delivers what is expected.
A widely used example of declarative programming is the HyperText Markup Language (HTML) that is used to design web pages and web apps. The language asks for various elements to be displayed on the web browser with tags but the exact interpretation of the tags is left to the web browser that display the HTML page.
The drawback with this approach is that the same program may execute differently (for example, the HTML page may look different depending on the browser used), however, generally all environments follow a standard so the difference is minimal.