Lab this week was spent learning more about class inheritance and unit testing. These were both parts of programming that I did not have a lot of experience with before this week. Creating classes have been getting much easier with the practice I have been doing between class exercises, labs and home programming. Practicing has helped speed up the lab, and focus on inheritance and unit testing. It was interesting using parent classes to handle repeat code as a more advanced version of building new functions to minimize repeat code. Inheritance helped me reduce the code written for the motorized and human-powered classes and further subclasses during lab.
Once the code was cleaner using inheritance, my partner and I moved on to unit testing. We both had experience with the assertEqual function but little else with unit testing. My favourite new function to learn was the assertRaises function because this allowed me to apply my newly gained knowledge of exceptions from last week. Personally, I love when topics connect so well in my courses, so being able to combine exceptions and testing together was very exciting.
Now I will be heading into the first assignment applying these new skills towards creating cleaner, more powerful code. I look forward to sharing my struggles and breakthroughs in my future posts.
I'm sure you have heard this a few times, but welcome to my SLOG! So this week we are going through my adventures of OOP (Object-Oriented Programming). I got a brief introduction to OOP back in CSC108 and now that I have started CSC148, the professor has been ensuring the students are more comfortable with OOP from the beginning. As the course has been moving through the year, I have learned a little bit more about OOP and Python as a whole. This week the professor focussed on exceptions in class and the TA was teaching us how to find and use new modules, both of which are a type of OOP but have very different aspects.
During class this week, the professor gave us our first introduction into raising and creating our own exceptions. As I've never created an exception subclass, this was a completely new concept to me. Creating my own exceptions has allowed me to utilize Python's class inheritance. While I enjoyed learning about creating exceptions, it wasn't the easiest concept to grasp from the beginning. To fully learn to independently execute this function, I not only had to review the lecture notes, but I had to rely on external research as well. I watched two very helpful YouTube instructional videos that gave me guidance on how to properly execute the exceptions. The most helpful video that I found was a tutorial from Lynda.com. This video was especially helpful because it uses live examples to demonstrate the functions, you can view it below.
Raising Exceptions Lynda.com Tutorial
By the end of exercise 2, I believe I know what each function now does and when to raise each one. While learning more about inheritance and subclasses, I was also learning about creating my own Abstract Data Types (ADTs) in our lab. We focused on creating stacks and queues and how each has its own strengths and weaknesses. At first, it seemed like stacks were far superior because the speed of using the stack class stayed constant as the inputs increased in size, while the speed of using the queue class increased linearly. During the lab the TA gave my partner and I recommended that we spend some of our own time researching new data types to use with the queues. While we were researching, we stumbled upon the collections module and the deque data type. When we implemented the deque data type into our queue, it increased the efficiency of the queue class to become constant like the stack.
I look forward to continuing my education of computer science and learning and becoming more self-sufficient as I work on my programming skills. While I expand my knowledge of computer science and improve my programming abilities, I will strive to enhance my blogging skills so that each post is interesting and helpful to my readers.