Programming Languages: A Comprehensive Overview PDF
Document Details
Uploaded by AlluringUkulele
Politechnika Łódzka
Tags
Summary
This document provides an overview of various programming languages, including binary code, assembly language, procedural, declarative, functional, and imperative programming. It explains the concepts, features, and benefits of each language type. The content also highlights the importance of structured programming in improving code readability and maintainability, as well as the advantages of OOP, modularity, and reusability.
Full Transcript
1. Binary Code / Machine Language Definition: The first generation of programming languages, consisting of sequences of binary numbers (0s and 1s) that the computer's CPU directly understands. Features: o Difficult: Very hard for humans to write and read....
1. Binary Code / Machine Language Definition: The first generation of programming languages, consisting of sequences of binary numbers (0s and 1s) that the computer's CPU directly understands. Features: o Difficult: Very hard for humans to write and read. o Error-prone: Small mistakes are common and can be hard to fix. o Expensive: Requires a lot of time and effort to create programs. o Low-level programming paradigm: The programmer works closely with the hardware using CPU instructions. Key terms: Batch-script: Early form of automating sequences of commands. Bug: A mistake in the code. 2. Assembly Language Definition: The second generation of programming languages. It uses mnemonics (symbols or short words) instead of binary numbers to represent CPU instructions. Features: o Replaces machine code with human-readable mnemonics. o Uses labels for memory addresses, making it easier to write and understand programs. o Low-level paradigm: Still works closely with hardware, but easier than binary. o Difficult to debug and maintain: Errors are still common and hard to fix. Key Points: Every function has a number: For example, to print something on the screen, you call a specific function using its number. int 21h: Ends a program. Labels: Help the programmer keep track of memory addresses. jmp (jump): A command that tells the program to go to a specific point in the code. Procedural Languages High-level languages designed for specific tasks: o COBOL: Business-oriented. o FORTRAN: Scientific and engineering problems. o ALGOL: Algorithmic definitions. o BASIC: Easy for beginners. All these languages follow the procedural (imperative) paradigm. Procedural Programming Summary 1. Key Concept: o The programmer specifies step-by-step instructions for how a task is accomplished. o These steps are written using language statements that describe a sequence of actions (algorithmic steps). 1. Declarative Programming Focuses on what the program should achieve rather than how to do it. The program describes the desired result, not the steps to get there. Examples: SQL, HTML. Key features: o Minimizes side effects. o Does not control the flow step-by-step. o Opposite of imperative programming, which gives detailed instructions. 2. Functional Programming A type of declarative programming. Programs are written using functions that: o Have inputs and outputs. o Do not use variables or change data (no side effects). o Recursion is heavily used (functions calling themselves). Key idea: Treat computation as the evaluation of mathematical functions. 3. Imperative Programming Specifies how the program works step-by-step to achieve a desired result. Example: Telling a robot each move to get from point A to point B. Focuses on control flow, like loops and conditionals. 4. Procedural Programming A type of imperative programming. Based on the concept of procedures (also called routines, methods, or functions). Procedures: o Contain a series of steps to be carried out. o Can be called at any point in the program. Examples: COBOL, FORTRAN, BASIC. Benefits of Procedural Programming: Reusability: o Code can be reused in different parts of the program without duplication. Easy to Manage: o The flow of the program is straightforward and easier to understand. Modularity: o Programs can be divided into smaller, manageable modules or functions. When to Use Procedural Programming: Suitable for simple sequential tasks. Works well when the program has moderate complexity. Ideal for programs that require easy maintenance and readability. Examples of Procedural Programming Languages: JavaScript Python C Procedural programming emphasizes the "how" of a task, focusing on breaking problems into smaller procedures or routines. Object-Oriented Programming (OOP) Definition: OOP is a programming paradigm that uses "objects" (data structures consisting of data fields and methods) and their interactions to design applications and programs. Key Features (Programming Techniques): o Encapsulation: Bundling the data (attributes) and methods (functions) that operate on the data into a single unit, like a class. It also restricts direct access to some of the object's components to enforce data protection. o Modularity: Dividing a program into separate, self-contained modules or components. Each module can be developed, tested, and maintained independently. o Polymorphism: The ability for objects to take on different forms. For example, a method might behave differently depending on the type of object that invokes it (e.g., method overriding in subclasses). o Inheritance: A mechanism by which one class can inherit the attributes and methods of another class, promoting code reuse and hierarchical classification. Historical Context: Although OOP concepts were introduced earlier, it didn't become widely used in the mainstream until the early 1990s. Popular languages like C++ and Java helped push OOP into the spotlight. Most Important Properties of Modern Programming 1. Efficiency/Performance: o Definition: Refers to how well a program utilizes system resources, such as processor time and memory space. The less resource consumption, the better. o Example: An efficient sorting algorithm like quicksort uses less processor time compared to bubble sort. 2. Reliability: o Definition: Measures how consistently a program produces correct results. o Key Factor: Depends on error prevention and handling. o Example: A calculator application that always returns the right mathematical results is reliable. 3. Robustness: o Definition: Indicates how well a program anticipates and handles errors, such as data type conflicts and runtime issues. o Main Focus: ▪ User interaction (e.g., input validation to prevent incorrect data entry). ▪ Exception handling (e.g., try-catch blocks in programming). o Example: A login system that gracefully handles incorrect passwords without crashing. 4. Usability: o Definition: Refers to how user-friendly a program is, focusing on making it easy to use. o Characteristics: ▪ Textual and graphical elements (e.g., clear menus, icons). ▪ Intuitive interfaces like GUI (Graphical User Interface) or touch interfaces. o Example: Mobile apps with simple navigation and responsive design. 5. Portability: o Definition: Refers to how well a program can run on different hardware and operating systems without modification. o Example: A Java program, written once, can run on any platform that supports the Java Virtual Machine (JVM). Formal Software Development Project Steps 1. Requirements Analysis: o Collecting and defining the functional and non-functional requirements of the software. o Example: Identifying that a library management system needs a feature for book search and lending. 2. Modeling and Creation of Software Project: o Designing the system architecture and data models. o Popular Technique: Object-Oriented Analysis and Design (OOAD). 3. Implementation: o Writing the actual code to develop the software. 4. Failure Elimination (Debugging): o Identifying and fixing bugs in the code. 5. Deployment: o Releasing the software for use by end users. 6. Maintenance: o Providing updates and fixing any post-deployment issues. Spaghetti Code Definition: Spaghetti code refers to unstructured and difficult-to-read programs. It often results from using: o Excessive and uncontrolled jumps (e.g., GOTO statements). o Poor or no modular design. Key Issues: o Difficult to Analyze: Debugging and maintaining such code becomes a nightmare. o Unstructured: There’s no clear program flow, making it hard to understand how the program operates. Visual Analogy: Just like a tangled plate of spaghetti, the program's flow of control is messy and intertwined. Avoidance: Structured programming and modular design practices are adopted to reduce these issues. Structured Programming Definition: A programming paradigm that emphasizes a clear, hierarchical structure for program flow. It makes code easier to read, debug, and maintain. Key Elements: 1. Sequence: ▪ An ordered execution of statements. The statements execute in order, one after the other. 2. Selection (Conditional Statements): ▪ The program decides which statements to execute based on a condition. ▪ Keywords: if...then...else. 3. Repetition (Loops): ▪ Executes a block of code repeatedly until a certain condition is met or for each element in a collection. ▪ Keywords: while, for, or repeat. ▪ Best Practice: Each loop should have only one entry point to avoid confusion. Key Benefits of Structured Programming 1. Readability: Clear and logical structure improves understanding. 2. Maintainability: Easier to debug and update. 3. Reusability: Promotes modular code that can be reused in different parts of a program. Compiled Languages Definition: These languages are converted directly into machine code through a compiler before execution. Once compiled, the program runs directly on the target machine without needing further translation. Examples: C, C++, BASIC, Lisp. Process: o Compilation: Translates source code into machine code. o The machine code is then executed directly by the computer hardware. Advantages: o Compiled programs generally run much faster because there is no need for runtime interpretation. o Efficiency makes them suitable for low-level applications like system software and performance-critical tasks. Disadvantages: o Longer edit-run cycles: Since you need to recompile the code after changes, development takes longer. o Complexity: A good compiler implementation can be challenging. Interpreted Languages Definition: These languages are executed using an interpreter, which processes the code line by line or block by block at runtime. Example: o Java: Translates its code into an intermediate form called bytecode (via compilation). The bytecode is then interpreted by the Java Virtual Machine (JVM). o Python: A classic example of an interpreted language, where Python code is executed by the Python interpreter. Process: o The source code is converted to an intermediate form (like bytecode). o This intermediate code is interpreted at runtime and translated to machine code. Key Concept: o Interpreted languages often rely on a virtual machine to execute code. o At runtime, the code is dynamically translated into native machine code. Combination of Both Many modern languages use a hybrid approach, combining compilation and interpretation: o Example: Microsoft.NET languages like C# are compiled into an intermediate form (CIL - Common Intermediate Language) and then converted to native machine code. Key Takeaways 1. Interpreted Languages: Flexible, easy to debug but slower due to runtime interpretation. 2. Compiled Languages: Faster execution but longer development cycles. 3. Hybrid Approach: Combines the benefits of both, common in modern programming environments.