Learn · Programming with Generative AI
Lecture 5 of 219Week 1 Part 1 Introduction
Test Your Understanding
Prof. Viraj Kumar · IISc Bangalore
Credits and licence
- From
- Programming with Generative AI, IISc Bangalore (at NPTEL)
- Licence
- CC BY-NC-SA, as NPTEL states it. Non-commercial use only.
- Attribution
- NPTEL states: "Distributed under Creative Commons Attribution-ShareAlike / CC BY - NC - SA", beside a BY-NC-SA badge.
- Who can watch
- Tweens profiles and older. How courses are placed
All the lectures
- What do Programmers Do?
- What is (and isn't) an algorithm?
- Algorithms for prime numbers
- Key Programming Trends
- Test Your Understanding
- How effective is GenAI at coding?
- Refuting an Algorithm
- Why is GenAI so effective at coding?
- Assumptions in AI-generated code
- Test Your Understanding
- Summary
- Python resources
- The REPL
- Basic Arithmetic Operators
- Test Your Understanding
- Complex Expressions
- Limits to arithmetic computation
- Investigation sys.float_info
- Binary digits (bits)
- Naming Things
- Introducing "our friend"
- Test Our Friend's Understanding
- Limits to float computation
- Python Objects
- Textual data
- Strings
- Summary
- Evaluating a complex expression
- Assignment statements in Python
- Assignment statements and a common misconception
- Clarifying the misconception
- Another misconception with assignments
- A final misconception with assignments
- Introduction to PythonTutor
- Swapping two variables (incorrect)
- Swapping two variables (correct)
- Good, Poor, and Illegal Variable names
- Summary
- Representing complex programs abstractly as functions
- Properties of mathematical functions
- Other built-in functions
- The input function
- Celcius to Fahrenheit (buggy)
- Reviewing our friend's critique of buggy code
- Debugging the code
- Nested function calls
- AI-generated program 1
- AI-generated program 1
- Another example: Patient Data (buggy)
- Using ChatGPT to debug
- Fixing ChatGPT assumptions
- Using GitHub Copilot to debug
- Further model assumptions
- Fixing GitHub Copilot assumptions
- ChatGPT vs GitHub Copilot
- Summary
- Poorly designed and well designed functions
- Principles of good function design
- Improvement 1
- Improvement 2
- Example of a poorly designed function
- Improvement 2 continued
- Improvement 3
- Simple conditional statements
- Critiquing AI-generated code
- Complex conditional statements
- Introduction to Refute problems
- Summary
- Example 1 (is_multiple)
- Visualizing Example 1
- Visualizing a function call
- The error in Example 1
- Fixing the code
- Key Observations
- Example 2 (modified is_multiple)
- Fixing the error, Simplification 1
- Elements of a Refute Problem
- Refuting the median function
- Simplification 2
- Feedback for Refute Problems
- Attempting to refute
- Refuting the num_days function
- Critique our friend's function
- Boolean/logical operators
- Simplification 3
- Identifying an unexpected behaviour
- Understanding and fixing the error
- Short-circuiting
- Inequivalence due to short-circuiting
- Summary
- Solving a problem with a helper function
- Calling a helper function
- Tracing a call to the helper function
- Definition of a leap year
- Refuting our friend's code
- Introduction to recursion
- Infinite recursion
- A correct recursive function
- Using the default visualization
- A non-recursive solution
- Refuting the buggy code
- Summary
- "Ask the Client" problems
- Clarifying the task
- Our friend's recursive function
- Tracing our friend's code
- Refuting our friend's code
- Clarifying questions: num_vowels
- Strings in Python
- Testing our understanding
- Testing out understanding further
- String operations and methods
- Testing your understanding
- Our friend's code: num_vowels
- Refuting our friend's code
- Immutable objects
- Summary
- Modifying existing code
- Poor code readability
- Improving code readability
- Asking clarifying questions
- Clarifying the code's expected behaviour
- Lists are mutable
- Step 1: Suggested modification
- Exceptions
- Tuples
- Sequence unpacking
- Summary
- A mystery (recursive) function
- Visualizing the mystery function
- A better (iterative) solution
- Visualizing a for-loop
- Pattern 1: Iterate until "success"
- Examples of Pattern 1
- An error in AI-generated code
- A buggy function using Pattern 1
- Refuting the buggy function
- Pattern 2: Accumulate
- The is_prime function
- Visualizing prime_product
- Another version of prime_product
- Visualizing the new version
- An example of Pattern 2
- Another example of Pattern 2
- Visualizing appending to a list
- Our friend's suggestion
- List comprehension
- A buggy function using Pattern 2
- Refuting the buggy function
- An interesting takeaway
- Summary
- A recursive mystery function
- Iterative version
- Replacing while with for: Example 1
- Replacing while with for: Example 2
- Searching in a sorted list
- Implementing binary search
- The num_unique function
- Incorrect implementations of num_unique
- A correct implementation of num_unique
- Visualizing num_unique
- An important case (nobreak with no iterations)
- Pattern 3: All pairs
- Example (Pattern 3): max_profit
- Refuting the buggy function
- Representing tabular data
- Basic dict operations
- Example: substring_count
- Clarifying the task
- Reviewing ChatGPT's solution
- Test Driven Development
- Writing doctests for is_prime
- Summary
- Clarifying the task: count_between
- Understanding the interpretation of "between"
- Are ChatGPT suggestions "good"?
- Generating the code after clarifying (using ChatGPT)
- Additional ChatGPT inputs
- Revised code after additional clarifications
- Learning a new programming language
- Python vs C: Similarities and differences
- Python: Example 1
- Translating Example 1 to C
- Key syntactic differences: Python vs C
- Visualizing Python and C code
- C programming style
- Python: Example 2
- Example 2, Attempt 2
- Semantics of integer division
- Example 2, Attempt 3
- Summary
- Example 1 (is_upper)
- Visualizing the incorrect is_upper function
- Correcting the error
- Basics of strings in C
- Strings in C (char [])
- Strings in C (char *)
- Mutable and immutable strings
- Example 2 (to_ind_lower)
- Visualizing the modified to_ind_lower function
- Our friend's translation
- Visualizing our friend's translation
- Preventing accidental mutation
- Copying a string (Attempt 1)
- Copying a string (Attempt 2)
- Fixing one error, revealing another
- Allocating memory on the heap
- Visualizing the revised version (with malloc)
- Summary
- Algorithm-centric improvements (to_ind_lower)
- Data-centric improvements (to_ind_lower)
- Processing textual data: C or Python
- Understanding (simplified) Python lists
- A simple implementation of Python lists (Part 1)
- A simple implementation of Python lists (Part 2)
- A simple implementation of Python lists (Part 3)
- A simple implementation of Python lists (Part 4)
- Testing the list implementation
- Summary