Lecture 01 Introduction

Joseph Haugh

University of New Mexico

Contact Information

  • Instructor: Joseph Haugh
  • Email: jhaugh@cs.unm.edu
  • Office: FEC 2170

A Little About Me

  • Masters in CS
  • Love Haskell
  • Love Video Games
  • Love Biking

Intro Questions

What Motivated You To Take This Course?

Intro Questions

How many of you have used AI?

Intro Questions

How many of you have used AI to program?

Intro Questions

What was your experience?

Intro Questions

Will AI replace programmers?

AI Is A Tool

  • Most of a programmers job is spent brainstorming and determining requirements
  • Actual time spent programming is relatively minimal
  • AI will help with this last part but not necessarily the other

The Difference Knowledge Makes

  • Think about a time you interacted with AI when you knew a lot about the topic
    • How did this change how you interacted with it?
    • Were you able to get a sufficient answer?
  • Now think about a time you interacted with AI when knew little about the topic
    • How did this change how you interacted with it?
    • Were you able to get a sufficient answer?

The Difference Knowledge Makes

  • When you have more base knowledge it makes it easier and faster to get good information from AI
  • If you want to get a job nowadays you need the base knowledge AND know how to use AI effectively
  • In this class I aim to start you down a path to attaining both

My AI Philosophy

  • I must preface this by saying this my take on AI and other professors view will be different tread carefully in each class
  • You may use AI to help you better understand code
  • You may not use AI to write code for you unless I explicitly allow it
  • Before you can effectively use AI to write code you need to know how to write it yourself
  • When in doubt ask me before you submit something

Reading Comprehension Understanding

  • Be careful of the trap of thinking you understand something just because you read about it
  • You must practice reading and writing code in order to develop understanding
  • This trap is exacerbated by AI
    • You submit an assignment to an AI
    • You read the solution
    • You say yeah that looks good
    • You test it and it works
    • You think you understood the assignment
    • Ask yourself honestly, good you solve that problem with no assistance on a test?

Coding Is Not A Spectator Sport

  • In every class you will be coding, this is the only way to truly learn
  • You must either:
    • Bring a personal laptop
    • Use one of the computers on the tables (these can be finnicky)
  • Ask questions!

Computer System

Computer System = Hardware + Software

Computer System

Computer System = Hardware + Software

  • Input Devices (keyboard, mouse, scanner, etc.)
  • CPU (Central Processing Unit)
  • Main Memory
  • Secondary Storage (thumb drive, CD, DVD, etc.)
  • Output Devices (screen, speaker, printer, etc.)

Computer System

Computer System = Hardware + Software

  • Operating System (OS)
    • collection of computer programs that control the interaction of the user and the computer hardware.
    • Examples: Unix, Linux, Mac OS, Windows.
  • Application Software
    • computer programs developed to assist a computer user in accomplishing a specific task.
    • Examples: text editor (vim, emacs), word processing application (Word or OpenOffice), browser (firefox, chrome, etc)

Computer Science

  • Computer Science is simultaneously about:
    • Science (duh!)
    • Engineering
    • Art

Human Languages

  • There are many human languages
  • Each varies in potentially profound ways
  • However, each aims to allow humans to communicate with other humans

Programming Languages

  • There are many programming languages
  • Each varies in potentially profound ways
  • However, each aims to allow humans to communicate with computers

Programming Requires Precision

  • Computers know nothing
  • It is up to us to program them from the ground up
  • Luckily the ground is higher than it used to be but the metaphor still applies
  • You must start to confront your preconceived notions to become a great programmer

Choosing A Programming Language

  • Programming languages are usually designed for a specific use case, be it:
    • Science
    • Math
    • Graphics
    • Systems
    • Learning
    • Art
    • Etc.
  • The choice can have profound effects on how you develop as a programmer
  • In this class we will learn Python

Why Python?

  • Python is widely used in many industries
  • Python is relatively easy to learn
  • Python is relatively easy to get up and running

What About Other Languages?

  • You might be asking well what about XYZ language isn’t it more popular/better?
  • Luckily programming knowledge transfers relatively easily between languages!

Printing

  • Let’s write a very simple Python program

  • This program will demonstrate one use of the print function

  • The print function allows us to send messages from the program to the user (you in this case)

  • Here is a program which prints: “Mon Ami”

    print("Mon Ami")
  • Notice that when we want to print a specific message we must put it in double quotes (““)

  • It is a common beginner mistake to forget these!

Doing Math

  • Let’s say we want to write a program which calculates the area of rectangle given its side lengths

  • What are the steps we need to take to get this to work?

  • We all know the following formula:

    area = length * width

  • How do we then turn that into a Python program?

    length = 5
    width = 6
    area = length * width 

Area Of A Rectangle

  • Formula: area = length * width

  • Program:

    length = 5
    width = 6
    area = length * width 
  • You probably have a few questions:

    • Why do we need 3 lines of code for 1 simple formula?
    • Do 5 and 6 have any meaning?
    • Could we change those numbers?

Play With The Code

  • To answer these questions lets play with this code in our textbook’s code editor

  • Copy the code from the previous slide into there and hit “Run Program”

  • What happens?

  • Nothing??!!

  • How do we actually see the area?

  • We need to print it!

  • Try this code:

    length = 5
    width = 6
    area = length * width 
    print(area)

Programming Languages Are Literal

  • A program will only do exactly what you say!

  • In our first version we didn’t tell it to print the area so it didn’t!

  • What would happen if we simply input the original formula version?

  • Try it:

    area = length * width
  • You get an error! Why?

  • In programming before you use a name you must first define it

  • This is why our program need 3 lines, we needed to first tell the computer what length and width were

Area Of A Triangle

  • Task: given a base and a height calculate the area of a triangle

  • Formula: $area = \frac{base * height}{2}$

  • Program:

    base = 2
    height = 4
    area = (base * height) / 2
    print(area)

Variables

  • You may be asking what does the equal sign (=) mean in Python?

  • Great question!

  • It differs from math

  • In math it means equality

  • In programming it means assignment

  • For example take the following code:

    x = 4
  • This tells the computer that when you refer to x from here on out you mean 4 until you change the value of x

Visualizing Program Execution

  • To see more concretely what I mean take the following code:

    x = 4
    print(x)
    x = 5
    print(x)
  • What will print?

  • Try it in the python visualizer