Welcome to CSCA08

TA name:: William Granados

Tutorial 08: Tuesday, 10:00 - 11:00, at BV355.

Practical 04: Tuesday, 12:00 - 13:00, at BV466.

Email Policy: Before emailing me, consider attending my practical or posting the question on Piazza. My email address is william.granadosmatamoros@mail.utoronto.ca. When emailing me, use your utoronto email and in the subject include "CSCA08".

Expectations: There may be a quiz held in tutorial, so please be on time.

Good luck on final exams!
Term test 2 will handed back this week.
If you haven't picked up all your quizzes, the next tutorial will be the last time to do so.
    Here's the description of the problem we solved notes and the final result
  • UML diagrams
    • Label inheritence with arrows, you generally want to inherit from classes which share several attributes/behaviours.
    • Use -/+ to destinguish between private and public variables or methods
    • When you list of parameters, you should indicate the types for everything except for the self variable.
    Here's the example gone over in class calendar
  • Classes
    • Classes have their own scope, so you can declare your own variables by doing self.var_name = val
    • The first method in a Class that it executed is the __init__ method.
    • When you call something like str(ClassName) the __str__ method is called.
    • When you call a sort method on a list containing classes, then the _lt_ method is called.
    Here's the example gone over in class calendar
  • Classes
    • Classes have their own scope, so you can declare your own variables by doing self.var_name = val
    • The first method in a Class that it executed is the __init__ method.
    • When you call something like str(ClassName) the __str__ method is called.
    • When you call a sort method on a list containing classes, then the _lt_ method is called.
    Here's the example gone over in class mutability_tracing. I've also created an extra example which I think should help clear up some content I went over
    If you find some examples confusing remember you can use Python Tutor to walk through the examples slowly
  • Shallow Copies
    • A shallow copy of a list essentially creates a new id for a list object in memory, but it still holds the same content of the original list
    • You can create a a shallow copy of a list by doing new_list = old_list[:]
    Here's the example gone over in class import_b, import_a
  • Importing files
    • You can import files/libraries using: import file_name
    • You can rename imports by doing import file_name as new_name
    • You can import specific variables or functions using "from" in your import: from file_name import func
  • Wing IDE Debugger
    • You can setup breakpoints in our code by clicking next to the line in wing
    • Debuggers basically give you a table for the memory model at every point in your code
    • Lots of terminology so checkout this link for my detailed info
    Here's the example gone over in class Example 1
  • Coding Style
    • Multiple return statements are bad and are harder to trace
    • Working code does not mean it's good code
    Here's the example gone over in class Example 1 and the test file we used Test 1
  • Design Recipe
    • Remember to follow the design recipe taught in class. For assignments and tests you will lose marks for not following them.
    • Very briefly, they are the following:
      • Header: good variable names, sensible function names, you should be able to get what's happening at a quick glance
      • Type Contract/REQs: what type of variables should be passed and restrictions on these variables
      • Description: focus on making it concise and descriptive
      • Examples: some simple examples so we can understand what our function does
      • Code: designing your algorithm
      • Commenting: describing relevant sections of your algorithm which aren't intuitive at first sight
      • Test: come up with a testing plan. For example try for each variable, coming up with important ranges/boundaries, then start testing important combinations.
  • Test Files
    • You can use the Test Runner website to run specialized testcases on your exercises and assignments. It will test your functions and fetch results
    • Each line is a testcase and each testcase is seperated by | characters. The format is 'function name|comma seperated values|comments|return value'
    • General tips when you're deciding on tests is to make a few general cases, then a couple of edge cases
    • Because you're doing design by contract you don't have to do anything special on invalid input, remember anything can happen so the fault is left on the user
    • If you're on windows you can save files with the extension '.test' by setting save type as 'all files' then writing in the file name section something like '.test'
    Here are the examples gone over in class Example 1, Example 2, Example 3.
  • Memory Model
    • Python Tutor is a good resource for visualizing the memory model. Choose "render all objects on the heap", "use text labels for references", and Python 3.6 to look at the version of the memory model we are accustomed with.
    Here's a modified version of the sample code gone over in class. Feel free to play around with it.
  • Difference between Python vs Wing
    • Python is the software you use to give instructions to the computer.
    • Wing, the IDE, is a software suite that helps you develop software.
  • Python version
    • You should be using Python 3.5+ when submitting excercises and assignments.
    • Major changes between Python 2.7 and Python 3. Some are listed here but you do not need to worry about them. Just make sure your IDE is configured to use Python 3.5+.
  • Difference between writing code in shell and writing code in file
    • You can declare variables in the python shell, do some computations, and echo values to stdout (standard output).
    • You should be writing all your exercises/assignments in python files. The Python shell is used for debugging or quick checks.
There are no tutorials this week. Instead here's a link to a funny comic Dilbert Programming Environment.