Prog lang reviewer.pdf

Full Transcript

Lesson 1: Introduction of Programming Languages Programming languages - Are formal systems used to instruct computers to perform specific tasks. They allow programmers to write code that the computer can interpret and execute. - At their core, programming languages consist of syntax an...

Lesson 1: Introduction of Programming Languages Programming languages - Are formal systems used to instruct computers to perform specific tasks. They allow programmers to write code that the computer can interpret and execute. - At their core, programming languages consist of syntax and semantics. Syntax - rules governing the structure of code. Semantics - meaning of the code. Categories of Programming Languages 1) High-Level Languages - These are designed to be easy for humans to read and write. They abstract away most of the hardware details. - Examples include Python, Java, and C#. 2) Low-Level Languages - These are closer to machine code and offer more control over hardware. - Examples include Assembly language and C. 3) Scripting Languages - These are often used for automating tasks and can be interpreted directly. - Examples include JavaScript, Ruby, and Perl. 4) Domain-Specific Languages - Tailored to a specific problem domain. - Examples include SQL and HTML Popular Programming Languages and Their Uses 1) Python - Known for its simplicity and readability - It is used in web development, data analysis, artificial intelligence, and automation. 2) Java - A versatile, object-oriented language used in enterprise applications, Android app development, and large-scale systems. 3) C++ - An extension of C, used for system/software development, game development, and high-performance applications. 4) JavaScript - Essential for web development, allowing for interactive websites and dynamic content. 5) R - Specialized for statistical analysis and data visualization. B. History and Evolution of Programming Languages 1) 1820s Charles Babbage - Constructed Difference Machine in the 1820s. - also pioneered the Analytical Engine, considered the first general purpose computer. 2) 1843 Ada Lovelace - a female mathematician who created the first machine algorithm in 1843. - She created the algorithm for the Difference Machine. - This algorithm gave rise to the first language for computers. 3) Early 1940s Konrad Zuse (Plankalkul) - In the early 1940s, Konrad Zuse created what is known as the first programming language. - Plankalkul was the first high-level programming language developed for computers. - It stored several codes engineers could use repeatedly to perform routine operations. 4) 1949 Assembly Language - In 1949, the Electronic Delay Storage Automatic Calculator (EDSAC) first used an assembly language. - Assembly language broke down the complex language of machine codes. - This low-level programming language simplified complex computer instructions. 5) 1949 Shortcode - In early 1949, John McCauley introduced Shortcode. - Shortcode didn't see widespread use until late 1949 and early 1950 when William Schmitt applied it to benefit the procedures of the BINAC and UNIVAC computers. 6) 1952 Autocode - In 1952, Alick Glennie coined the term Autocode. - As one of the first computer programs, Autocode became known as "a family of programming languages." - Glennie used Autocode for the Mark 1 computer. - Autocode translated machine code through a special program known as a compiler. 7) 1957 FORTRAN - In 1957, John Backus created FORmula TRANslation (FORTRAN). - It is the oldest computer programming language still in use today. - FORTRAN's development solved many problems in: 1. Mathematics 2. Science 3. Statistics - FORTRAN is used to solve complex statistical and mathematical problems. - Its versatility and wide range of applications made FORTRAN's creation a critical moment in the history of programming languages. 8) 1958 ALGOL and LISP - Algorithmic Language (ALGOL) and List Processor (LISP) are both important to the history of programming languages. - Both were created in 1958 by several European and American computer scientists. - They served as the platform for many other programming languages, including: 1. C 2. C++ 3. Java 4. Pascal - John McCarthy created LISP for Artificial Intelligence (AI) purposes. - LISP is one of the oldest computer programming languages still in use today. - Many people and businesses continue to rely on LISP instead of newer languages like Python or Ruby. 8) 1959 COBOL - Dr. Grace Murray Hopper invented COmmon Business Oriented Language (COBOL) in 1959. - This was a significant milestone that impacted many widely used programming languages. - COBOL is the backbone of many different systems and technologies, including: 1. ATMs 2. Cellular devices 3. Credit card processors 4. Traffic signals - COBOL was designed to run on all types of computers. - Today, banks rely on COBOL for their various banking systems. 9) 1964 BASIC (Beginner’s All-Purpose Symbolic Instruction Code) - Students at Dartmouth College created the (BASIC) in 1964. - Its purpose was to help students with little knowledge of computers and math. - Later, Paul Allen and Bill Gates worked on this compiled programming language. - BASIC became Microsoft’s first sold product. 10) 1970 PASCAL - Niklaus Wirth created PASCAL. - He named it after the famous mathematician Blaise Pascal. - PASCAL was designed to help people learn how to use programming languages. - Apple became a top supporter of PASCAL due to its simple and easy assembly language. 11) 1972 Smalltalk - Alan Kay, Dan Ingalls, and Adele Goldberg designed Smalltalk to help computer programmers adapt to new programming languages. - This led to the creation of popular programming languages such as: a) Java b) Python c) Ruby 12) 1972 C - Dennis Ritchie created the C language to use with the Unix operating system. - Ritchie named it "C" because it came after an earlier language, B. - Apple, Google, and Facebook are among the top tech companies using C functional programming today. - C is still used with the Unix operating system. 13) 1972 SQL (Structured Query Language) - Donald Chamberlain and Raymond Boyce created SQL to modify and view important data stored on computers. - Many businesses, including Accenture and Microsoft, use SQL today. - SQL remains one of the most popular programming languages. 14) Early 1980s Ada - Jean Ichbiah led the construction of Ada. - The language was named Ada Lovelace in honor of the pioneering mathematician. - Ada is a high-level programming language used to control air traffic in various countries, including: 1) Belgium 2) Germany 3) Australia 15) 1983 C++ and Objective-C - In 1983, Bjarne Stroustrup evolved the C programming language into C++. - C++ introduced new features that C didn’t have, such as Classes, Templates, Virtual functions - Other popular programming languages also emerged during this time. - Award-winning C++ gained attention from tech giants and is used in many programs, including: Microsoft Office, Gaming platforms, Adobe Photoshop (one of the first to use C++) - Tom Love and Brad Cox created Objective-C in 1983. - Objective-C is the leading programming language used for all Apple’s operating systems, including: iOS, macOS 16) 1987 Perl - Perl was launched in 1987 by Larry Wall. - Initially created for text editing, Perl is now used for various purposes, including: Database applications, Graphic programs (graphical user interface), Network programs 17) 1990 Haskell - Haskell was introduced in 1990. - Named after Haskell Brooks Curry, a famous mathematician. - This language assists with mathematical procedures. - Many businesses use Haskell as a common business-oriented language. - Some in the industry believe its use was also for the creation of video games. 18) 1991 Visual Basic - 1991 was a significant year in computer programming. - Microsoft launched Visual Basic, a popular programming language. - Enabled users to drag and drop code through a graphical user interface. - Allowed individuals to select and modify large sets of code at once. 19) 1991 Python - Python was also introduced in 1991. - Created by Guido Van Rossum. - Provides support for various programming styles. - Ranks as the most popular programming language today. - Widely used by tech companies, including Google and Instagram. - Python has had a major impact on the programming world. 20) 1993 Ruby - In 1993, Yukihiro Matsumoto developed Ruby. - Its web development was inspired by various languages, including: - Ada (one of the oldest programming languages) - LISP - Perl - Smalltalk Companies that use Ruby include: Hulu, Groupon, Twitter 21) 1995 Java, JavaScript, and PHP - James Gosling created Java for an interactive television project. - It is one of the most favored programming languages used today on cellular devices and computers. - Brendan Eich developed JavaScript in 1995. - Aimed at helping individuals create webpages, browsers, widgets, and PDF documents. - Almost every major website uses JavaScript. - Hypertext Preprocessor (PHP) was introduced in 1995 as Personal Homepage. - Its goal was to assist individuals and businesses in building and updating websites. - Several companies still depend on PHP, including: Wikipedia, WordPress, Facebook 22) 2000 C# - Microsoft launched C#. - Designed to merge the computing features of C++ with Visual Basic’s simplified features. - C# is similar to Java but derived from C++ and Visual Basic. - All Microsoft tools and products use C#. 23) 2003 Scala - Scala was created by Martin Odersky. - A mathematical programming language compatible with Java. - Essential for Android development. - Companies using Scala today include: 1. Foursquare 2. LinkedIn 3. Netflix 4. Twitter - Groovy was developed by Bob McWhirter and James Strachan. - Originated from Java. - Aimed to improve efficiency and production. - Starbucks uses Groovy for its daily tasks. 24) 2009 Go - Google launched Go. - Created to address issues that arise in larger software systems. - Features a modern and easy-to-use structure. - Companies that use Go include: Uber Google Twitch 25) 2014 Swift - Apple implemented Swift. - Replaced Objective-C, C++, and C. - Aimed to create a simpler and easier language than its predecessors. - Offers versatility for use on: 1. Cellular devices 2. Cloud applications 3. Desktop computers Old Programming Languages Still in Use Today 1) FORTRAN 2) COBOL Other programming languages still in use 1) BASIC 2) C 3) LISP 4) Pascal 5) Smalltalk These languages are used for - General-purpose programming - Object-oriented programming - Scripting large software systems Today’s Most Popular Programming Languages - Go - HTML/CSS - Java - JavaScript - Python - SQL - Swift -.NET/C# Lesson 2: Introduction to Python Python - is one of the most widely used programming languages today, known for its simplicity, readability, and versatility. It has become a popular choice for a range of applications, from web development and data analysis to machine learning and automation. A. History of Python 1. Early Beginnings (1980s-1990s) a) Conception and Development: - Python was created by Guido van Rossum, a Dutch programmer, in the late 1980s. - Van Rossum started working on Python as a successor to the ABC language, which was designed to be an easy- to-read language for teaching and prototyping. He wanted to create a language that combined the best features of ABC with the strengths of Unix and C. b) Python 0.9.0 (1991): - The first public release of Python, version 0.9.0, was made in February 1991. - This early version already included many features that are still present in Python today, such as exception handling, functions, and modules. 2. Growth and Evolution (1990s-2000s) a) Python 1.0 (1994): - This version introduced important features such as the lambda keyword, map, filter, and reduce functions. Python's syntax and structure started to solidify. b) Python 2.0 (2000): - Python 2.0 introduced many new features, including list comprehensions, garbage collection, and Unicode support. - This version marked a significant step in Python's evolution, making it more powerful and versatile. c) Python 2.x Series - Python 2.x continued to evolve with many incremental improvements, including new syntax features and standard library enhancements. 3. Modern Era (2000s-Present) a) Python 3.0 (2008): - Python 3.0, also known as "Python 3000" or "Py3k," was a major redesign of the language to fix fundamental design flaws. - It introduced several breaking changes to make Python more consistent and readable. - Features like print as a function, new string formatting methods, and improved division operations were part of this release. b) Python 3.x Series: - Since Python 3.0, the language has continued to evolve with numerous updates. - Python 3.6 introduced f-strings for easier string formatting, Python 3.7 added data classes, and Python 3.8 brought assignment expressions (walrus operator :=). - Python 3.9 introduced new syntax features like type hinting and dictionary merging. 4. Current Status - As of 2024, Python is in its 3.x series, with Python 3.11 being the latest stable release. Python's popularity has continued to grow, driven by its use in web development, data science, machine learning, and automation. B. Features of Python 1. Readable and Maintainable Code Simple Syntax: Python’s syntax is designed to be clear and easy to read. For example, Python uses indentation to define code - blocks instead of braces or keywords. 2. Dynamically Typed Type Flexibility: Python does not require explicit type declarations. Variables are dynamically typed, meaning the type is determined at runtime. 3. Interpreted Language On-the-Fly Execution Python code is executed line-by-line by the Python interpreter, which simplifies debugging and allows for interactive testing. 4. High-Level Language Abstraction from Hardware: Python provides a high level of abstraction from the underlying hardware, which allows developers to focus on problem- solving rather than system-level details. 5. Extensive Standard Library Built-in Modules: Python comes with a vast standard library that includes modules for file I/O, system calls, data manipulation, and more. This reduces the need to write code from scratch. 6. Object-Oriented Classes and Objects: Python supports object-oriented programming (OOP), allowing for the creation of classes and objects to model real-world entities. 7. Functional Programming Support First-Class Functions: Python supports functional programming features like higher-order functions, anonymous functions (lambdas), and list comprehensions. 8. Cross-Platform Platform Independence: Python is available on various platforms, including Windows, macOS, and Linux. Python code can often be executed on different systems with minimal modifications. 9. Extensible and Embeddable Integration with Other Languages: Python can be extended with C/C++ modules and embedded in applications written in other languages. This allows for performance optimization and integration with existing codebases. 10. Large Community and Ecosystem Active Community: Python has a large and active community that contributes to a rich ecosystem of third-party libraries and frameworks. Tools like NumPy, Pandas, Django, and Flask are widely used in various fields. Lesson 3: Basic Syntax and Data Types in Python A. Python Syntax and Indentation Python's syntax and data types are fundamental to writing and understanding code 1. Syntax Basics Statements and Expressions Python code is composed of statements and expressions. A statement performs an action (e.g., variable assignments, function calls), while an expression evaluates to a value. Comments Comments are used to explain code and are ignored by the interpreter. Single-line comments start with a #, and multi-line comments can be created using triple quotes (""" or '''). 2. Indentation Block Structure Python uses indentation to define code blocks. This is a departure from many other languages that use braces {}. Consistent indentation is crucial as Python relies on it to group statements. Indentation Level Typically, an indentation level is four spaces. Mixing tabs and spaces can lead to errors, so it's best to stick to one method. B. Variables and Constants 1. Variables Definition and Assignment Variables are used to store data values. In Python, you can assign values to variables without explicitly declaring their type. Naming Conventions Variable names should be descriptive and follow certain conventions. They must start with a letter or underscore and can include letters, digits, and underscores. Python is case-sensitive, so myVariable and myvariable are different. 2. Constants Convention Python does not have a built-in way to define constants. However, by convention, constants are written in uppercase letters with underscores separating words. Usage Constants are used for values that should not change throughout the program. While Python doesn’t enforce immutability, adhering to naming conventions helps maintain code clarity. C. Data Types 1. Integer - Integers are whole numbers without a decimal point. They can be positive, negative, or zero. - Basic arithmetic operations include addition, subtraction, multiplication, and division. 2. Floats - Floats represent real numbers with a decimal point. They can also be positive or negative. - Floats support the same arithmetic operations as integers, with the added precision of decimals. 3. String - Strings are sequences of characters enclosed in single quotes ('), double quotes ("), or triple quotes (''' or """ for multi-line strings). - Strings support concatenation (+), repetition (*), and various methods such as.lower(),.upper(), and.strip(). 4. Boolean - Booleans represent truth values and can be either True or False. - Boolean operations include logical AND (and), OR (or), and NOT (not). D. Type Conversion 1. Implicit Conversion - Python automatically converts between types when necessary, such as when performing arithmetic operations between integers and floats. 2. Explicit Conversion - Using Built-In Functions: You can explicitly convert between data types using functions like int(), float(), str(), and bool(). Handling Invalid Conversions - Some conversions may raise errors if the conversion is not possible, such as converting a non-numeric string to an integer. Methods and functions in Python, along with their types. A. Built-In Functions 1. input() - The input() function is used to read a line of text from the user via the console. It takes an optional string argument, which is displayed as a prompt to the user. The function returns the user's input as a string. 2. print() - The print() function outputs text or other data to the console. It can take multiple arguments and automatically separates them with spaces. It also adds a newline character by default after printing the content, but this behavior can be modified with optional parameters. 3. max() - Returns the largest of the input values. 4. sum() - Returns the sum of all the items in an iterable (e.g., a list). 5. len() - Returns the number of items in an object (e.g., length of a string or list). B. Method 6. count() - Counts the number of occurrences of a specified substring in a string. 7. lower() - Converts all characters in a string to lowercase. 8. upper() - Converts all characters in a string to uppercase. 9. strip() - Removes any leading and trailing whitespace characters from a string. C. Function from the math module 10. math.factorial() - Computes the factorial of a non-negative integer. Lesson 4: Basic Concepts of Programming Languages A. Syntax vs. Semantics Syntax - refers to the set of rules that define the structure of valid statements in a programming language. It dictates how symbols, keywords, and operators must be arranged to form correctly structured programs. - Syntax ensures that the code follows the correct format and structure, enabling the compiler or interpreter to understand and process it. - In Python, syntax errors occur when the code deviates from the language's rules. Semantics - refers to the meaning of the statements in a programming language. It defines what the code does when executed, as opposed to how it is written. - Semantics ensures that the code performs the intended operations and produces the expected results. - Semantics errors occur when code is syntactically correct but doesn't achieve the desired outcome. B. Compilation vs Interpretation I. Compilation - is the process of translating the entire source code of a program into machine code (binary code) before execution. This is done by a compiler, which produces an executable file. Advantages: 1. Performance - Compiled code usually runs faster because it is translated directly into machine code. 2. Error Checking - Compilation often catches syntax and semantic errors before execution. Examples: C/C++ - Programs written in C or C++ are compiled into executables. The gcc compiler is commonly used for this purpose. II. Interpretation - involves translating and executing code line-by-line or statement-by-statement at runtime. An interpreter processes the source code directly, without producing a separate executable file. Advantages: 1. Flexibility - Interpreted languages allow for dynamic execution and easier debugging. 2. Portability - Interpreted code can run on any platform with the appropriate interpreter. Examples Python - is an interpreted language. The Python interpreter executes the code line-by-line. Hybrid Approach - Some languages use a combination of both compilation and interpretation. For example, Java is first compiled into bytecode, which is then interpreted or JIT-compiled by the Java Virtual Machine (JVM). C. High-Level vs. Low-Level Languages I. High-Level Languages - High-level languages are designed to be easy for humans to read and write. They provide a high level of abstraction from the hardware, using natural language elements and complex data structures. Characteristics: a) Abstraction: High-level languages abstract away hardware details and memory management. b) Ease of Use: They are generally easier to learn and use due to their readability and simplicity. Examples: - Python: Known for its readability and ease of use, Python abstracts many of the complexities of lower-level languages. - JavaScript: Used primarily for web development, JavaScript provides high-level abstractions for web interactions and dynamic content. II. Low-Level Languages - Low-level languages are closer to machine code and provide minimal abstraction from the hardware. They offer greater control over hardware resources and memory management but are more complex to use. Characteristics: a) Hardware Interaction: Low-level languages interact closely with hardware, making them suitable for system programming and performance-critical applications. b) Complexity: They are often harder to learn and use due to their intricate syntax and need for manual memory management. Examples: - Assembly Language: A low-level language that uses mnemonics to represent machine code instructions. It is specific to a particular computer architecture. - C: While C is often considered a high-level language, it provides low-level memory manipulation features and is used in system programming. Comparison of High-Level and Low-Level Languages: a) Abstraction: High-level languages abstract hardware details, while low-level languages provide direct hardware access. b) Ease of Use: High-level languages are more user-friendly, whereas low-level languages require detailed knowledge of hardware. c) Performance: Low-level languages often offer better performance due to closer hardware interaction, but high- level languages can be optimized with modern compilers and interpreters.

Use Quizgecko on...
Browser
Browser