NE111: Introduction to Programming for Engineers
Table of contents
1 Preamble
1.1 Learning Outcomes for the Course
Here is the official course description:
Introduction to programming and numerical computing using a high-level interpreted programming language. Programming fundamentals, computer architecture, design and use of functions, strings and text input/output, relational operators, conditionals, lists, loops, designing algorithms, numerical computing, plotting, and file input/output.
Let’s translate these buzz words into plain English:
- “Introduction to programming” \(\rightarrow\) We will assume you have zero knowledge of programming
- “numerical computing” \(\rightarrow\) We will use computers as super powerful calculators
- “using a high-level interpreted programming language” \(\rightarrow\) We will use Python because it’s way easier than C/C++
- “Programming fundamentals” \(\rightarrow\) We will cover Python but the building blocks are common to all computer languages
- “computer architecture” \(\rightarrow\) We need an appreciation of this so we can get the most from the computer in terms of speed
- “design and use of functions” \(\rightarrow\) We will use functions to hide complicated logic
- “strings and text input/output” \(\rightarrow\) We sometimes need to read and write text to and from the computer
- “relational operators” \(\rightarrow\) We often need to decide if something is less than, greater than, equal to, something else
- “conditionals” \(\rightarrow\) We can tell the computer to do A if B is True, otherwise do C
- “lists” \(\rightarrow\) We can store multiple pieces of data in a sequence for later use
- “loops” \(\rightarrow\) We can scan through our lists of data to do calculations
- “designing algorithms” \(\rightarrow\) We will develop logical steps to obtain a numerical answer
- “numerical computing” \(\rightarrow\) We will use some special tools to make this happen
- “plotting” \(\rightarrow\) We will plot our results for easy visualization
- “file input/output” \(\rightarrow\) We will save our results to a file for later use
Given the above list, we can formulate a set of learning outcomes for the overall course:
Upon completion of this course you should:
- …know the syntax and features of Python quite well
- …appreciate the role of the underlying computer hardware on the performance of a computer program
- …use functions to create “code” that is concise, organized and readable
- …control the order of execution of a program using relational operators and conditional statements
- …store and retrieve data from Python’s various data containers such as lists
- …use for-loops to scan data stored in various containers and perform calculations as needed
- …develop multistep numerical calculations to compute results, such as scientific calculations
- …use state-of-the-art libraries to extend Python’s capabilities to scientific calculations
- …visualize data using a variety of graph styles
- …read and write data from memory
1.2 Outline
The official course outline is posed online via the Outline tool.
The course is broken up into 2 sections: “Before Midterm” (BMT) and “After Midterm” (AMT). Midterms occur in Week 7 (Oct 14-18) but Week 6 is a reading week. This means that we have 5 weeks of BMT, and 6 weeks of AMT.
Week | Description |
---|---|
Week 1 | Introduction to Python: Installing Python; learning syntax; mathematical expressions; variable assignment; using, importing, and writing functions. |
Week 2 | Data Types and Collections: Understand data types; working with collections; iterating through collections. |
Week 3 | Logic and Flow Control: Introduction to Boolean logic; use of relational operators; applying logic to collections; controlling execution. |
Week 4 | Working with Text: Deep dive into strings; converting and formatting strings; performing operations on strings. |
Week 5 | Files and IO: Introduction to the file system; reading and writing files; installing external libraries; introduction to version control. |
Week 6 | Reading Week |
Week 7 | Midterm Week |
Week 8 | Writing Pythonic Code Crafting advanced functions; documenting functions; dealing with error conditions; using collections fully; mastering comprehensions; mastering for-loops. |
Week 8b | Creating Data Dashboards: Using Streamlit to create graphical user interfaces. (During the make-up lecture on Nov 1) |
Week 9 | Numerical Computing with Numpy Part 1: Overview of computer architecture; compiled vs interpreted languages; introduction to the Numpy library; overview of related libraries. |
Week 10 | Numerical Computing with Numpy Part 2: Multidimensional arrays; fancy indexing; applications in linear algebra. |
Week 11 | Data Management and Visualization: Reading and writing numerical data; introduction to Pandas; plotting with matplotlib and other available libraries; working with images. |
Week 12 | Introduction to Object Oriented Programming: An introduction to OOP principles; classes; inheritance; data encapsulation. |
1.3 Learning Approach
1.3.1 Learn by Doing, then Redoing
“To begin, begin”
- William Wordsworth
This course is designed to deliver the material “iteratively”. This means that we will cover the topics several times:
- The first time we see a concept, we will skip over many of the details. Instead we will focus on the rough outlines with just enough detail to do something useful.
- On subsequent passes over a concept we will fill in the gaps by focusing on more features and gaining an understanding for what is actually happening and why.
- This also means that the first way I show you how to do a task might not be the best way.
1.3.2 The Forgetting Curve
The Forgetting Curve shown in Figure 1.2 is one of my favorite mental models of learning. The point is that we don’t learn something by looking at it once. We need to revisit the material periodically before it become a permanent part of our personal knowledge base.
In the context of this course, this means two things:
- You should not expect yourself to remember every single detail of Python after the first introduction. So don’t be mad at yourself for forgetting bits and pieces. It’s normal to look-up how certain things work and it’s why good documentation is hugely important.
- The notes have been written like a manual that can be read later (i.e. 1st review, 2nd review, etc). You should come back to these notes on your own time and re-read them. The downside of this approach is that lectures will include us reading over the notes together which may seem a bit tedious.
1.3.3 On the use of AI
The policy for generative AI in this course is:
It is forbidden on all the assignments and exams.
However, it will be allowed on the project. We don’t want to be total Luddites, so we’ll introduce the use of AI at the appropriate point.
There are two reasons for this policy:
It is still considered crucial that engineers know how to code well. AI can deal with the tedious bits of coding like formatting graphs, writing boilerplate, scrapping data from websites, formatting data in files, etc. AI is very good at these simple things because it has been trained extensively on this sort of standard code. However, as engineers we are often asked to solve problems that are very specialized and involve a lot of real-world considerations. These are often called ‘edge cases’. AI may struggle with these tasks, so you will have to take the wheel and do this sort of coding yourself. This happens to be the hardest sort of coding which requires you to have a lot of skill.1
1 AI can easily handle all of the content we will cover in this course, because it is an introductory course. Do not let this convince you that AI can handle everything. In my experience, AI has never given me perfect code on the first try. I always have to iterate 2-3 times. And I usually have to tell it what it got wrong…like “the methods get_values
does not exist on the data
object, are you sure you’re using the latest version?”
AI can generate lots of code quickly, but as the programmer you need to still understand what it has produced. You need to know if the code is very inefficient, or has a security flaw, or a memory leak, etc. Basically, when AI hands you a bunch of code, you still need to understand it.