01 Intro
Programming Lanugage¶
Tool for humans to communicate with a computer system
We should try to generalize a programming language, to ensure compatibility.
Properties¶
- Turing Complete Must be able to express anything computable
- Must be able to implement on existing hardware platforms
What makes a good language?¶
- Syntax close to what we are used to
- Readability
- Expressibility For eg,
while
loop instead ofif
andgoto
- Reliability: Error Checking
- Detect use of initialized variables
- Type checking
- Array Bounds (C vs Java)
- Testing Support
Paradigms¶
Imperative | Declarative | |
---|---|---|
Programmer tells __ to do | how | what |
Focus of programming language | Do exactly what is told | Do what is meant |
Classifications | - Procedural: Fortran, C - Object-Oriented: C++, Java - Scripting: Python, Javascript, Bash(Shell) | - Functional: LISP/Scheme/Haskel, symbolic data processing - Logic: Prolog, Logic Reasoning - SQL: mySQL, PostgreSQL, Cassandra, NoSQL |
- Sequential - Concurrent |
Why do we usually use imperative languages?¶
As we mainly use von Neumann machines, which is the class of stored program digital computer.
Imperative languages give control over moving data and program instructions between registers in CPU and Memory location
von Neumann Architecture¶
There is no distinction between code and data, as they are stored in the same memory
Structured Programming¶
Dijkstra
Also referred to as โgoto-lessโ programming
- Single entry, Single exit sequence
- Selection
- Repetition
Generations¶
Language Generation | Description | Language Translator required | Example | Performance |
---|---|---|---|---|
Machine | This is what your machine understands | None | ๐ฅ | |
Assembly | Mnemonics (names and symbols) | Assembler | x86 MIPS | ๐ฅ |
High-Level | - Machine independence - Semantics not limited to machine architecture - Human-Friendly - Data/Control Flow abstractions - Availability of libraries - Consistency check (data types) | Compiler Interpreter | C C++ Fortran Pascal | ๐ฅ |
4th Gen | Interpreter | Python | ๐ | |
5th Gen | Just-in-Time Compiler | Julia | ๐ฅ |
In the present-day, compiler-generated code is faster than human-written assembly code; it was not the case before
Bugs¶
Programming testing can be used to show the presence of bugs, but never their absence!
~ Dijkstra
Solution¶
- Organize code modularly, such that each part can be understood
- Alpha Testing by company testers
- Beta Testing by end-users
Early Programming Languages¶
Year | Language | Full Form | Creator | Purpose | Focus | Still Used? |
---|---|---|---|---|---|---|
1954 | Fortran | Formula Translator | J Backus (IBM) | Numerical Computing | Efficiency | โ |
1958 | ALGOL | Algorithmic Language | J Backus (IBM) F Bauer (TU) | Algo \(\to\) Programs | Clarity Elegance | โ |
1958 | LISP | List Processor | J McCarthy (MIT) | Symbolic Computing | Abstractions | โ |
1959 | COBOL | Common Business Oriented Language | G Hopper (US Navy) | Data Processing (Payroll) | โEnglish-likeโ | โ |
Scripting Language vs Programming Language¶
Programming languages
- follow EBNF(Extended Bacus Normal Form)
- have CFG(Context-Free Grammar)
Language Translators¶
Compiler | Interpreter | Virtual Machine | |
---|---|---|---|
Speed | Faster | Slower | |
Error Detection | Harder | Easier | |
Code Processing Method | One-Go | Line-by-Line | |
Translation | Once | Every execution | |
Distributes | Executable | Executable not possible | |
Development time | Slower | Faster | |
Typing | Static/Dynamic | Dynamic | |
Target Program | Machine Code Portable Machine Code (Java Byte Code) C Code | โ Does not generate target program executes instructions directly | |
Example | C C++ Java | Javascript Python | Java Python |
Compiled Code¶
flowchart LR
subgraph "Once"
sp2[Source Program] --> Compiler
end
Compiler --> tp2
subgraph "Every Execution"
tp2[Target Program]
i2[/Input/] --> tp2 --> o2[/Output/]
end
Interpreted Code¶
flowchart LR
subgraph "Every Execution"
direction LR
sp2[Source Program] --> Interpreter
i1[/Input/] --> Interpreter --> o2[/Output/]
end
Virtual Machines¶
flowchart LR
subgraph "Once"
sp2[Source Program] --> Compiler --> ip["Byte Code<br />(Intermediate Program)"]
end
ip --> vm[Virtual Machine]
subgraph "Every Execution"
i2[/Input/] --> vm --> o2[/Output/]
end
combine the plus points of compiler/interpreter
Interpreting high level code is slow
Java¶
Python¶
- First time the program is run, it is interpreted
- In subsequent runs, the cached byte code
.pyc
is executed
RAM¶
Random Access Memory
Stores program instructions, addresses, and immediate values
Shell Scripts¶
View resources consumption by various users