Monday, 27 January 2014

exercise 2 finished + what I learned + things

    Exercise 2, at least to me, was about practicing making our own error messages. It was very straightforward, but before starting with this exercise, I needed some help from a friend to teach me some new python commands and concepts that I didn't learn in CSC108 (or in class either, because I wasn't paying close enough attention):

-Every error message you get in python comes from a built-in class called 'Exception'.

This is important for making your own customized error messages, because in order for those customized messages to work like any other error message, you must make a new subclass of Exception. 

-The command 'raise'.

raise is needed for when you want to call a class. If I wanted to call a subclass Customized_error that I made to display my customized error message, I would write the following line in my code:
raise Customized_error("customized error message")

-The commands 'try' and 'except'.

'try' is used for when you want to run a function to see if an error is caused, but not return what the function is supposed to return. 'except' is to be written after try, then followed by the name of an error class or subclass. If that error class or subclass is reached during the call of the function, the line acts very similar to an if statement that returns True, and the program then decides to run the code that is written within the indent of this 'except' line.

    This was basically everything I needed to learn in order to finish the exercise. Other than that, my new time slot on Monday-Wednesday mornings is working out much nicer for me, but I've lately been giving more attention to my other courses. This will probably change I hope. Yes.

Sunday, 19 January 2014

Week 3: Object-Oriented Programming

    Object-oriented programming is a way to write code by creating your own types for the objects you create, via classes. These types are designed to make an object store data in the same way that object stores data in real life. The type for an object that was made through a class is typically a combination of types that are already built-in to the programming language. For example, In CSC108 last semester, we practiced with a class called "Day" in python. The type of a "Day" object is a combination of 4 pieces of information: day, month, year, and events.  In specifically this case, day and year are integers, month is a string, and events is a list. Any of these pieces of information can be called to in a very visually-friendly manner, and I think this might be the reason why we like Object-oriented programming so much and why we're supposed to get used to doing a lot of it, especially in our larger, more complicated programs.

feeling disoriented

    After checking my email, I realized I need to make weekly blog posts in addition to 3 other specific posts, so here is my first one. I was enrolled in the 6-8 Wednesday lecture at first, and I missed the first one because my flight from vacation was delayed. I went to the second week's lecture and I realized this lecture simply wasn't right for me. I went onto ROSI and am now enrolled in a Monday-Wednesday morning lecture time table, so I'll have to see how this one works out.
    The only thing I managed to learn about in class was recursion. The most notable example of the recursion for me was in the function for adding all of the numbers in a nested list. The English translation for the piece of python code that used recursion in that function goes like this: "If the current iteration is looking at an inner list instead of a number, then run the function again for that inner list."
    I know in this blog I'll soon have to write something specific about object oriented programming, so my next course of action is to read about that from the links on the course website.