Introduction to Course and Basic Programming Concepts

Jul 12, 2024

Lecture 1: Introduction to Course and Basic Programming Concepts

Instructor Introduction

  • Instructor: Anna Bell
    • First name: Anna, Last name: Bell
    • Almost 10 years of teaching experience in the ECS department
  • Course: 6100L
  • Focuses on introductory programming, particularly in Python
  • Interactive lectures with coding breaks (UTRI breaks)

Course Overview

  • Main Goals:
    1. Knowledge of Concepts
    2. Programming Skills
    3. Problem-Solving Skills
  • Diverse resources and handouts for extra practice
  • Participation and practice are key for mastering programming

Course Content

  • Core Topics:
    • Computational thinking
    • Python programming language
    • Code organization (neat, readable, modular)
    • Introductory algorithms
    • Algorithmic complexity (efficiency and memory usage)
  • Lecture Structure:
    • Introduction to concepts
    • Interactive coding segments with UTRI breaks
    • Opportunities for questions and group discussions

Types of Knowledge

  • Declarative Knowledge vs. Imperative Knowledge
    • Declarative: Statement of fact
    • Imperative: A recipe or how to do something
  • Computer science relies on imperative knowledge

Example: Finding Square Root

  • Declarative statement: The square root of X is Y such that Y * Y = X
  • Imperative recipe:
    1. Start with an initial guess (e.g., 3 for sqrt(16))
    2. Check if guess squared is close enough to the number
    3. Iterate with a new guess averages

Understanding Algorithms

  • Algorithms are sets of instructions with flow control and stopping conditions
  • Recipe analogy: Steps, control flow, and stopping
  • Computers execute algorithms line by line
    • Good at storing data and performing operations quickly
    • However, computers only do what they’re programmed to do

Brief History of Computers

  • Early Computers:
    • Fixed-program computers (e.g., calculators)
    • Stored-program computers and interpreters
  • Key Components:
    • Memory storage
    • Arithmetic Logic Unit (ALU)
    • Control Unit with a Program Counter

Programming Languages and Python Primitives

  • Alan Turing’s Contribution:
    • Foundational principles of computation with simple operations
  • Python Primitives:
    • Numbers
    • Sequences of characters (strings)
    • Operations (addition, subtraction, etc.)
    • Truth values (booleans)
  • Key Primitives:
    • Integers (int)
    • Floating-point numbers (float)
    • Booleans (bool)
    • Special value None for no data

Using Python Shell and IDLE

  • Shell: For quick checks and small experiments
  • IDLE: For more extensive code editing

Creating and Using Variables

  • Variables: Names bound to values for storage and retrieval
  • Syntax:
    • variable_name = value
    • Left side of assignment is variable, right side is value or expression
  • Examples:
    • pi = 3.14159
    • radius = 2.2
  • Rebinding: Variables can be reassigned new values
    • Example: radius = radius + 1

Expressions in Python

  • Syntax: object operator object
  • Types of operators define actions like addition, multiplication, comparison
  • Operator Precedence: order of operations in expressions
    • Parentheses can change precedence

Using Commands and Expressions

  • Type Command: Determines the type of an object (e.g., type(7) -> int)
  • Examples:
    • int(5.9) truncates to 5
    • float(3) converts to 3.0

Variable Naming Conventions

  • Use descriptive names for readability
  • Avoid single letters unless in simple, short scopes

Writing Programs with Good Style

  • Comments for explanation and clarity
  • Consistent, meaningful variable names
  • Tidy structure and indentation

Programming Errors

  • Types of Errors:
    • Syntactic: Spelling and incorrect syntax
    • Static Semantic: Type-related errors
    • Semantic: Logical errors in meaning or expected outcomes

Debugging with Python Tutor

  • Helpful for stepping through and visualizing code execution line by line

Summary

  • Concepts: Programming involves creating and manipulating objects
  • Types: Objects have types which define allowable operations
  • Expressions: Combine objects into evaluable expressions
  • Variables: Name objects for reuse and clarity in programs
  • Line execution: Programs run line by line sequentially unless directed otherwise in later lessons
  • Computers follow exact instructions, hence correctness is crucial

Next lecture: Decision points and flow control in programs.