Thursday, January 30, 2014

Week 4: Starting A1

A1 was released a little while ago, and I've been working on parts of it here and there.  So far, the assignment seems pretty straightforward: finish the code in TOAHModel, get a console version of the game running, then actually write a method to solve the game using as few steps as possible.  Most of TOAHModel has been finished (the method headers, actual implementation), and not many errors were encountered on the way, which is really good considering how frustrating it is to look over every line of code hoping to find the mistake.

The _cheese_at docstring could have been much clearer--I didn't really know what it was asking for at first and I'm still not sure when to call the method.  Right now, the only thing left to do in TOAHModel is to finish writing the number_of_moves method; in principle, it should be easy to write it: just return the length of the MoveSequence associated with the TOAHModel object.  For some reason, however, I can't wrap my head around how to actually declare MoveSequence within the __init__ method (to be more precise, what should the argument be?).  Hopefully, I'll manage to figure this out within the next couple of days...not very worried about this since I understand the problem.

What I am sort of worried about though is how to write the solution to this problem.  In class, Heap mentioned that the code for Tour did not necessarily need to have recursion (although having it definitely makes it easier)--I would love to be able to see how someone might do this once A1's handed in.  Still, the thought of this method makes my head spin, so I'm trying to steer clear of thinking about this until I have to (or maybe it's because I want to avoid using my brain??).

Wednesday, January 22, 2014

Week 3: Object-oriented Programming

Python's main focus is geared toward OOP, which--in a nutshell--allows people to create different objects and assign them attributes and methods.  Although we have much left to talk about in class, I can already see how OOP plays such an important role in computer science.  Not only will it allow programmers to create effective and efficient code to model real-world objects and trends, but its applications are immense: business, science, entertainment, healthcare--it surrounds us.

We've recently discussed how to create new classes, methods, and attributes, and even dabbled on inheritance.  Objects can be assigned unique traits and be made to perform specific actions (methods), which isn't all that different from their real-life counterparts.  Likewise, the concept of inheritance is similar to its counterpart, in which the parent class passes on its methods to child classes; a child class can override its inherited methods by substituting different code, and even create new methods of its own.  I'm a little bit sketchy as to how effective multiple inheritance is, because it seems to me that creating a new (non-child) class would be much less confusing, especially when the parent classes contain many unnecessary methods that would be passed down.  In class, the Stack and IntStack examples showed the basics of OOP (its components, creation) as well as in what circumstances inheritance would be useful (when two classes perform related tasks).  I'm currently having a little trouble understanding the __repr__ method, so I will probably read up and write some examples to catch up.

Having done Java in the past, OOP is pretty familiar to me.  What I find interesting, and would definitely like to learn more about, are the similarities and differences between Java and Python ways of object creation.  What are the strengths and weaknesses of each?  It seems like neither language should hold a greater advantage than the other considering that they both do the same thing (create objects), but then why would there be two languages?  I'm curious as to what others think of languages and OOP in general: do you think it's a difficult topic to understand at this time and is Python object-programming much different than what you've done in the past?