Programming Languages
- A language is a medium for communication.
<aside>
💡 Programming languages communicate computational instructions.
</aside>
- Originally , these languages were directly connected to the architecture → Low level Language.
- In this design, memory locations would store the values and registers were used to do arithmetic operations.
- e.g.: Doing a simple addition operation of two values:
- Load a value from memory location $M$ into Register $R_1$.
- Load another value from memory location $M'$ into Register $R_2$.
- Add the contents of register $R_1$ and $R_2$ and store back the result in $R_1$.
- Write the value in $R_1$ to desired location $M_r$.
- As seen above, this was tedious and error prone. Simple operations required many instructions.
- As a solution to this problem , a concept of abstraction was introduced.
Abstractions
Various abstractions are used. Abstractions simply means showing only useful information and hiding the rest.
- Some abstractions we may have seen:
- Assigning values to named variables. (Instead of assigning it to a specific memory location in the memory).
- Conditional Execution. ( To execute a bunch of statements if some condition is satisfied)
- Iterations.
- Functions, procedures and recursion.
- Aggregate Data Structures - arrays, lists, dictionaries.
- These are high ideas and needed some mechanism to translate these into low level language that is understood by the computers.
- Compilers and Interpreters are such mechanisms.
- What is the catch?
- We will have less control over how the code is mapped to the architecture. So we may not be able to optimize the code to the highest level possible.
- But there are now fewer errors and takes less time to code.
So there is a trade off between expressiveness for efficiency.
Styles of Programming
- Two specific styles of programming: Imperative v/s Declarative.
Imperative
- Focuses on: How to compute.
- Step by Step instruction on what is to be done.
Declarative