How is everyone's week so far? My keyboard broke over the weekend so I ordered one off of e-bay and for the first time took apart a laptop to get it fixed up. Turned out A-OK :]. My profs and friends had a good laugh at it though, especially since I was copy pasting the letter E to take notes.
So what's new in weeks 3-4? Well let's dive right in.
Overview
- Diving deeper into recursion
- Inheritance
- Clarification on ADT's
- Testing code
- MORE FRIGGIN AWESOME BUILT IN FUNCTIONS!
Recursion
Cool stuff. Three visual examples of recursion were shown to us this week: Koch, Turtle and Sierpinski's triangle fractals. All of the functions work the same way, that is, they call themselves repeatedly until the code tells it to stop. If the code doesn't specify a stopping point, they will keep calling themselves recursively until your system runs out of memory!
One really interesting thing that I noticed in the turtle recursive example was that each time it calls on itself, the function spawns 3 times the turtle of the previous function call. It starts with 3 turtles, one spawning at 0 degrees, another spawning at 120 degrees and the third spawning at 240 degrees. Then another 3 turtle spawns at each of the previous end points following the same degree order! So we have 3 turtles on the first call, 9 turtles on the second, 27 on the third... ETC.
So we can conclude mathematically that it behaves as 3 to the n'th power where n is the number of specified (or unspecified!) calls.
Why is computer science so cool?
Inheritance
This is a really neat property in Python that allows us to combine other classes and how they work into a totally new class. Even though we can borrow from other classes, it has been mentioned that multiple inheritance should be totally avoided since things can get pretty confusing if multiple classes have the same functions. However, I wonder if it would be problematic at all if we combined classes that do not have multiples of the same functions. Hmmm..
ADT's
My previous post about ADT's was made totally clear to me by one of the professors in 148. So here it is: We have been using ADT's such as the built-in functions. These built-ins (isinstance, str, abs, ETC.) were programmed for our use without us having to worry how they were implemented. SUPER SIMPLE!
Testing Code
My weakness lies here. Out of habit, I test my own code without using doc tests or unit tests. During this week's lab, I was totally dependent on my partner for this part of the exercise. I actually know how to use doc testing but not unit tests. They are a bit harder to use as you have to write your own classes to perform them. They are however, much more reliable on finding bugs in the program than doc tests.
New Built-In Functions
raise allows us to call on our own defined Error Types! For example: If I were to follow coding design guidelines, I could raise a user-defined error if some programmer's code had lines longer than 80 characters *Cough, me, cough*.
exception allows our program to catch errors and tell it what to do if it encounters an error. Perhaps a client might use our program incorrectly, inputting a list of some sort instead of an int. If the program uses exception, we could easily add a little bit of code that will notify the client that the program will only take inputs of integers!
isnumeric checks if a string consists of an integer and returns True or False. I was lucky to learn of this built-in through a classmate in my lecture which helped me tons in the second exercise.
Check back next week for more awesome CSC stuff!
Comment and ask away if you please.
Ciao
Why is computer science so cool?
Inheritance
This is a really neat property in Python that allows us to combine other classes and how they work into a totally new class. Even though we can borrow from other classes, it has been mentioned that multiple inheritance should be totally avoided since things can get pretty confusing if multiple classes have the same functions. However, I wonder if it would be problematic at all if we combined classes that do not have multiples of the same functions. Hmmm..
ADT's
My previous post about ADT's was made totally clear to me by one of the professors in 148. So here it is: We have been using ADT's such as the built-in functions. These built-ins (isinstance, str, abs, ETC.) were programmed for our use without us having to worry how they were implemented. SUPER SIMPLE!
Testing Code
My weakness lies here. Out of habit, I test my own code without using doc tests or unit tests. During this week's lab, I was totally dependent on my partner for this part of the exercise. I actually know how to use doc testing but not unit tests. They are a bit harder to use as you have to write your own classes to perform them. They are however, much more reliable on finding bugs in the program than doc tests.
New Built-In Functions
raise allows us to call on our own defined Error Types! For example: If I were to follow coding design guidelines, I could raise a user-defined error if some programmer's code had lines longer than 80 characters *Cough, me, cough*.
exception allows our program to catch errors and tell it what to do if it encounters an error. Perhaps a client might use our program incorrectly, inputting a list of some sort instead of an int. If the program uses exception, we could easily add a little bit of code that will notify the client that the program will only take inputs of integers!
isnumeric checks if a string consists of an integer and returns True or False. I was lucky to learn of this built-in through a classmate in my lecture which helped me tons in the second exercise.
Check back next week for more awesome CSC stuff!
Comment and ask away if you please.
Ciao