Friday 13 February 2015

W6: OOP too OP for me

    It's finally time for a "break". Our first term test and a1 results have been returned. I have been kicking myself for the stupid mistakes I made on the term test. I wish I had checked it over, but I was literally writing until the very last second before the exam invigilator said, "stop writing, pencils down!". Besides that, I am satisfied with both results and really wish I could take a break; instead, a2 for both my csc148 and csc165 classes have been released and I am once again, thrown into a state of panic.
 
    Looking back to the start of the semester, I must say, I have improved my understanding of many things in the course. I felt we were a little rushed in the end of csc108 so I wasn't comfortable with classes when we started csc148, but now I feel a lot more confident, as well as with other OOP concepts .

Everything in Python is an object, they are, what we call, "the basic building blocks".

Classes
Why do we use classes? Mainly to have a sense of "togetherness", so that functions we use are not separate but can be grouped, in which they become methods. Somewhat similar to its cousin, def. In classes we are able to define attributes and methods. An attribute is a characteristic of an object, such as a salary of an employee. Methods are operations we can perform with our object; for example, a cancellation of an account. During the first week or so, I was still getting familiar with the structure and design of implementing classes, as well as the special methods: __init__, __str__, __repr__, and __eq__.

Subclasses:
A (sub)class (or "child class") derived from the parent class; an analogy commonly used to portray classes and their subclasses. These are generally more specific for particular cases, than what the parent class covers, as well as having the ability to override certain methods of the parent class.

Have you heard about the object-oriented way of becoming wealthy?
No...?
Inheritance.

Inheritance:
As defined by Google, "derive (a quality, characteristic, or predisposition) genetically from one's parents or ancestors"). It's basically the same in programming as well. Subclasses, children, inherit "characteristics/attributes" from classes, parents. Here, they are inheriting methods and data that have already been written. One important rule of programming is, "DRY", Don't Repeat Yourself (as I've learned how "lazy" some fellow programmers are haha).

Property:
Trying to make something "private" but not exactly. We do this by adding two underscores "__" 's in front of a variable/function and Pythonista's (as Prof. Heap calls fellow programmers), are expected to realize and respect that code. Means you're not supposed to change it, but there's nothing actually stopping you from doing so.

#well this wraps it up for now.

Thursday 5 February 2015

W5: Re-re-re-re-cursion recap

    Clever functions they are, recursive functions. Really, it's inception, I think my first understanding still holds true, "code-ception". As I mentioned in last week's post, our "introduction" to recursion; this week was more of a hands-on experience. Tracing them in last weeks lab, as well as the in class exercises was good practice. I think, once you figure out the "pattern" or "trick", the rest is easy to see.

    Since our first term test was this week, working on my aid sheet also helped prepare me to be capable of writing code on paper. The night before the test, my fellow classmate and friend, Tim, and I were discussing as well as taking turns quizzing each other with content we predicted would be covered on the test. One thing I learned from him, because I didn't exactly trace the recursive question he asked me correctly, is to TEST until the pattern is discovered. Which actually makes pretty good sense, if you don't know what it does, throw something in and see what it spits out. I don't get everything like this *snaps fingers*, like some (most) of my cs friends but I try my best to figure it out and learn.
Still, there are times when this happens:
But practice, practice, and more practice! :)

    As for this week, we had one lecture on Monday, the test was Wednesday (which I thought was okay), and I just had my lab this morning. Today's lab, we focused on the A(bstract) D(ata) T(ypes)'s, stacks and queues. We worked first with Stacks, understanding their attributes and writing code to implement use of them, then we did a similar exercise with queues. The slight difference between Stacks and Queues lays in their LIFO and FIFO difference. Elements of Stacks follow the rule, "last in, first out", while Queues follow the, "first in, first out" rule (much like a lineup at Starbucks- first in line, gets their "java" first). In the lab I was also familiarized with the if __name__ == "__main__": block. Still, I always have my questions about programming :P
    

Sunday 1 February 2015

W4: If at First You Don't Succeed, You Must be a Programmer.

    Well, that sure went by pretty quickly. On January 9, 2015, I remember thinking, "why. is. this. first. week. taking. so. long.", but I seem to have just skipped through the second and third week. I attended one of the ramp-up sessions  because I felt a refresher would be of benefit, even though I just took csc108 last semester.


This picture accurately describes how I feel about computer science at times.  
The first weeks started with some confusion but I think I'm starting to get right into things. The biggest adjustment, I think, from csc108, is the change in lecture style. 

    Csc108 was run as an inverted class- which I enjoyed and found very helpful. 
(1) we had in class work-sheets, the opportunity to see if we understood the material and was capable of implementing it ourselves; and if not, ask the prof or the TA's!
(2) the amount of questions asked was also significantly higher (in my opinion), I find sometimes in lecture, people are too shy, or don't necessarily get the opportunity to ask question(s). Maybe several which are common among students. 
(3) sometimes, in lecture, I see the example and I think, "yeah, I could've come up with that", when in reality, it probably would've taken much effort but because I saw it, instead of trying it myself, I thought I could.

  As I adjust to the lecture style of csc148, I realize that the weekly labs have definitely been of help to me because I have the chance to apply what we've learned about in lecture, in practice. The labs are also more specific, focusing on one aspect at a time with a TA available to look at your work and answer questions or explain certain things. This also allows for me to figure out what I am uncomfortable with or uncertain about and ask for help with.

Recap: 
_______________________________________________________________________

As for week four, I didn't know why my friends were so excited, but now I see.

def. Recursive loop: See "recursive loop". 

    To be honest, I had never done programming before I decided to study it in university. In the summer, before I came to Toronto, my very talented friend Paul, who self taught and self learned programming taught me some programming- or attempted to, is probably the better phrase. I worked with Java for maybe a period of three weeks with him as my instructor. We'd meet once a week for a lesson and then he'd give me an assignment to complete for the next class. I must say I did learn a great deal of things from him, but I didn't understand everything as a whole at the time; it all started being pieced together and making sense in 108. We didn't really start with the basic foundation, but rather, the basic concepts, and one of the concepts he taught, was recursion. 

    My general understanding of recursion at the time was, "so it's like code-ception..." This understanding, is somewhat correct, but there's definitely more to it. I've taken a look back at the assignment I had to do in Java over in the summer, which was to make a recursive method that will return based on a given index, the corresponding term of the Fibonacci sequence. For those of you that don't know, the Fibonacci sequence is formed by adding two numbers before the current term together (first two numbers of the sequence are 0 and 1); looking back now, I have a better understanding. In lectures, as well as this week's lab we've been practicing tracing recursive functions of different depths as well as writing our own simple little recursive function. Tracing, I think, helps to understand it. 

People often joke, that in order to understand recursion, 
you must first understand recursion.