Thursday, 27 February 2014

Week of Feb 27th:

Learned alot about OOP this week in studying for the midterm and starting a2:

I now understand inheritance much better, and I see that the __init__ and __eq__ methods are just that: methods: I had a hard time as I thought they were somehow different from any other methods, but after working through the boundedStack Subclass and IntStack subclass exercises I understood how their inheritance actually works as I had to call it form my superclass Stack:

I became much better at one statement recursions after going through the nested_depth and max_depth examples and now have no problem using them on the fly. My issue was that I was not comfortable not seeing it a usual loop structure (my TA presented it to us like this) and hence I could not easily identify the base case when seeing it in one line, but after trying it out a few times it finally clicked.

For linked lists this week, my partner was away (for which I am grateful), and I got to do the whole lab by myself, so I felt like I learned twice as much. I had no problems reimplementing the queue as a Linked List but spent an hour trying to make sure it decapitates like a queue and not a stack; I'm still not clear on this so I will have to ask my TA next week.

I also realized why I was having such a hard time with init before: my shell doesn't allow me to define the class types for self and other input variables in the init statement, so all the programs I wrote before would never run in my shell and I didn't get why; I also can't use the ) -> bool/object/None,etc: to end off my inits, but once I figured this out everything has been much easier.

I did almost all of a2.1 today; in fact I had alot of fun. My regexes work exactly like trees; for me the biggest challenge was getting the correct __repr__ for say, regex1, but then removing the quotation marks when regex1 was used as an input in some other regex2. I solved this by assigning a self.value within each regex's init that holds its actual character and then using the repr to just add outside ' 's to the self.value; I've been able to successfully duplicate every compound regex on the assignment sheet so far so I assume it works!

One error I made today was to write if regex == s statements for each regex's __eq__ method, but I see now that for more complex and longer regexes this might not work. Instead, I need to redefine them recursively using the input regex __eq__ methods, so that

regex==s becomes regex1.__eq__(s) etc.This will link it back to the base case, which is the single length regex eq method.

Also sorry this entry is late, I completely got carried away with a2!

No comments:

Post a Comment