First Contact - Part 2 813
First Contact - Part 2 813
Programming
Fundamentals
Dr. Barroon Isma’eel Ahmad
Department of Computer and Information Technology
Photo by Pexels
01 Study Session 1: Introduction to Computer Programming
Table of 02
03
Study Session 2: Basic Data Types and Variables
Study Session 3: Object-Oriented Concepts
Contents 04 Revision
05 Study Session 4: Program Organization and API Usage
06 Study Session 5: Event-Driven Programming
07 Study Session 6: Input/Output and Control Structures
08 Study Session 7: Recursive Algorithms and Inheritance
09 Revision
10 Study Session 8: Polymorphism
11 Study Session 9: Project Development
12 Revision
13 Revision
2
Introduction to Programming Fundamentals
● An overview of the core concepts of programming including variables, loops, and functions.
● Understand the importance of coding in modern-day technology and its applications in various industries.
● Explore the fundamentals of programming languages, syntax rules, and problem-solving strategies.
● Delve into the significance of structured programming and algorithmic thinking in software development.
● Discover the evolution of programming languages and the role of programming paradigms in shaping software
design.
● Learn about object-oriented programming and its advantages in creating reusable code.
● Understand the key principles of software testing, debugging, and version control.
● Explore common programming errors and methodologies to enhance code quality and maintainability.
● Reflect on the ethical considerations in software development and the importance of adhering to coding standards
and best practices.
● Explore the interdisciplinary nature of programming and its impact on innovation.
3
Course Aims
4
Course Objectives
5
Week 1
6
Learning Outcomes
7
Overview of Computer Programming
● Computer programming is the process of designing and writing instructions that the computer follows to perform specific
actions.
● These instructions are written in a code format that computers can interpret and execute.
● Importance: Automates tasks, solves complex problems, and enables the development of software, apps, and websites.
● Programming Languages: There are many programming languages, each with its own syntax and rules.
● Some popular ones include Python, Java, and C++. While each language looks different, the core concepts of
programming apply across them all.
● Goal-Oriented: Before you start coding, it’s crucial to have a clear goal in mind. Whether you’re building a game, creating
a website, or tackling a complex problem, a clear objective helps guide your programming efforts and gives direction to
your code.
● Benefits and Opportunities
○ Problem-Solving: Programming helps us solve problems by automating solutions and performing calculations.
○ Efficiency: Automates repetitive tasks, improves productivity, and ensures accuracy.
○ Innovation: Essential for the development of new technology and digital transformation.
○ Career Opportunities: Learning programming opens doors in fields such as web development, AI, data analysis, and cybersecurity.
8
Core Concepts in Programming
● Variables: These are like containers that hold information (data) within your program. You can think of them as storage
units for values like numbers or text that you can use and manipulate in your code. Variables are foundational, helping you
store, organize, and change data as needed.
● Control Flow: This determines the order in which instructions are carried out in a program. Using conditional statements
(like if statements), loops (like for and while loops), and functions, you can control how the program responds to certain
conditions, how it repeats actions, and how it performs specific tasks.
● Debugging: No matter your skill level, you’ll encounter errors (or “bugs”) in your code. Debugging is the process of finding
and fixing these errors, and it’s an essential skill for every programmer. Debugging may seem challenging, but solving
these issues is often satisfying and helps improve your programming skills.
● Problem-Solving: Programming is largely about problem-solving. Often, you’ll face complex tasks that require you to think
critically and devise creative solutions. Don’t worry if you don’t solve every problem instantly—programming is about
breaking problems into smaller parts and tackling them step-by-step.
● Continuous Learning: Programming is a rapidly evolving field, with new languages, frameworks, and technologies
emerging all the time. Staying curious and open to learning is vital as a programmer, so be ready to explore new tools and
techniques as you grow. 9
Programming Paradigms
● A programming paradigm is a style or way of programming. Each paradigm offers a unique approach to solving
problems through code.
● Understanding different paradigms expands your programming skills, enabling you to choose the right approach for
each project.
● Examples of Paradigms:
○ Procedural
○ Object-Oriented
○ Functional
○ Event-Driven
○ Imperative
○ Declarative
○ Structured
○ Logic
○ Concurrent
10
Programming Paradigms
● Procedural Programming: Organizes code into procedures or functions that execute in a specific sequence to
complete tasks.
○ Focus: Step-by-step execution of instructions, suitable for problems broken down into smaller tasks.
○ Example Language: C, Fortran, Pascal
○ Example Code: Writing functions like calculateSum or findMaximum to handle specific parts of a program.
○ Applications: Common in scripts, algorithms, and projects with linear workflows.
○ Advantage: Easy to understand and debug.
● Object-Oriented Programming (OOP): Focuses on objects, which are instances of classes that encapsulate data and
behaviors, representing real-world entities.
○ Key Concepts:
■ Classes & Objects: Templates for creating objects.
■ Encapsulation: Keeps data safe within objects.
■ Inheritance: Shares properties between classes.
■ Polymorphism: Allows one interface for different implementations.
○ Benefits: Promotes code reusability, modularity, and maintainability.
○ Example Language: Java, Python, C++
○ Example Code: In a game, define classes for Player, Enemy, and Weapon with unique data and behaviors.
○ Applications: Software development, game development, GUI applications.
11
Programming Paradigms
● Functional Programming: Emphasizes pure functions, which have no side effects and don’t modify external state.
○ Focus: Declarative code that’s easy to understand and maintain.
○ Benefits: Functions are predictable and reusable; ideal for complex calculations or data transformations.
○ Example Language: Haskell, Lisp, JavaScript (with ES6)
○ Example Code: Using functions like map and reduce to transform data in JavaScript.
○ Applications: Data analysis, machine learning, and applications needing predictable, state-independent behavior.
○ Advantage: Simplicity and easier to test/debug.
● Event-Driven Programming: Code responds to events or user actions, such as clicks, keypresses, or API responses.
○ Key Concept: Event Handlers that execute when events occur, allowing asynchronous and concurrent programming.
○ Benefits: Enhances user interactivity and responsiveness in applications.
○ Example Language: JavaScript, Visual Basic, C#
○ Example Code: In a web app, create a button click handler that updates content or sends data to a server.
○ Applications: Ideal for UI design, web development, and network programming.
12
Programming Paradigms
● Imperative Programming: Focuses on describing how a program should execute, with explicit instructions for each
step.
○ Characteristics: Often involves mutable state and step-by-step logic.
○ Example Language: C, Python, Assembly
○ Example Code: Writing code to update a database or process file input/output sequentially.
○ Applications: Used in system programming, database handling, and other tasks requiring a specific sequence of
operations.
● Declarative Programming: Specifies what the outcome should be, not how to achieve it.
○ Focus: Simplifies complex tasks by letting the system handle the steps.
○ Example Language: SQL, HTML, CSS
○ Example Code: Writing SQL queries to retrieve data from a database without specifying how it’s processed.
○ Applications: Common in database management, configuration management, and user interface frameworks (e.g.,
React).
13
Programming Paradigms
● Structured programming: is a paradigm that emphasizes clear, logical flow in code by using control structures like
sequences, conditionals, and loops. It avoids the use of "goto" statements to create more readable and maintainable
code.
● Key Principles:
○ Modularity: Divides the program into smaller, manageable functions or modules. Each module performs a specific task, making the
code easier to understand and debug.
○ Control Structures: Uses three main structures:
■ Sequence: Executes statements in a specific order.
■ Selection: Makes decisions with if-else or switch statements.
■ Iteration: Repeats actions using loops, like for, while, or do-while.
○ Top-Down Design: Breaks down a problem into smaller sub-problems, which can then be solved individually. This approach keeps
each section of code focused and manageable.
● Benefits:
○ Improved Readability: Code is easier to read, follow, and maintain due to the logical structure.
○ Ease of Debugging: Modular structure and control flow simplify finding and fixing errors.
○ Reusability: Functions and modules can be reused across different programs, reducing redundancy. 14
Programming Paradigms
15
Programming Paradigms
● Logic Programming: Based on formal logic, where facts and rules drive decision-making and problem-solving.
○ Key Language: Prolog
○ Example Code: Setting rules like "If A is true, then B must be true" to derive conclusions.
○ Applications: AI development, knowledge bases, and natural language processing.
● Concurrent Programming: Enables multiple tasks to execute concurrently to improve performance and
responsiveness.
○ Methods: Uses threads, processes, or other mechanisms to achieve concurrency.
○ Benefits: Boosts efficiency and is crucial in applications handling multiple simultaneous tasks.
○ Example Language: Java, Go, Python (with threading/multiprocessing libraries)
○ Example Code: Running multiple tasks in a server application, like handling multiple user requests at once.
○ Applications: Common in multithreaded servers, real-time applications, and games.
● Summary
○ Each paradigm offers unique tools and perspectives for solving problems.
○ Choosing a Paradigm: Consider the requirements and goals of your project to determine the best paradigm.
○ Experimentation: Practice with different paradigms to expand your versatility and problem-solving skills.
○ Embrace the strengths of each paradigm, and you’ll grow as a more capable and adaptable programmer.
16
Scripting Languages
● Scripting languages are high-level programming languages used to automate processes or add functionality to
existing software. Scripts typically run inside larger programs, like browsers or operating systems.
● Examples:
○ Python: Easy-to-learn and versatile, used in web development, automation, data analysis, and AI.
○ JavaScript: Primarily used for web development, allows dynamic interaction on websites.
○ PHP: Used for server-side web development.
○ Bash: Used for writing shell scripts to automate tasks in Unix-based systems.
● Advantages:
○ Easy to learn.
○ Interpreted at runtime, so no need for compilation.
○ Great for quick automation and web development.
● Benefits of Scripting Languages
○ Ease of Use: Minimal setup required, great for beginners.
○ Rapid Development: Scripting languages allow quick creation and testing of programs.
○ Flexibility: Widely used across different fields, from web development to automation.
○ Large Libraries: Many built-in libraries for tasks like file manipulation, data analysis, and networking.
17
Scripting Languages
18
Application of Programming Paradigms
● Web Development
○ Uses multiple paradigms: scripting for the front end (JavaScript) and procedural/object-oriented programming for the back end
(PHP, Python).
○ JavaScript handles event-driven behavior like button clicks or form submissions.
● Mobile App Development
○ Often relies on object-oriented programming (Java, Swift) to organize app features into classes and objects.
● Game Development
○ Uses object-oriented principles to model characters, items, and actions as objects.
○ Event-driven programming manages user inputs like key presses or clicks.
19
In-Class Activity - Understanding Paradigms
● Task: Break into groups and compare the four programming paradigms discussed
○ Procedural vs Object-Oriented
○ Functional vs Event-Driven
● Discussion Points
○ How would each paradigm handle a real-world problem (e.g., building a basic calculator)?
○ What are the advantages and drawbacks of each paradigm?
20
Summary
21
Recap: Key Takeaways
22
Assignment
● Write a short program in Python (or any scripting language) to calculate the sum of two numbers provided by the
user.
● Ensure that you follow structured programming principles (e.g., meaningful variable names, modularity).
● Group Discussion: Reflect on how programming paradigms can be applied to real-world problems.
23