In Week 7 I discussed recursion, and the method by which I was originally taught how to implement recursive code. I said that when I was first learning recursion " I was taught to never try and trace the program, but instead rely on constructing robust base cases, and sound logic in making the recursive calls."
Upon working a bit more with recursion I still think this is one of the best ways to introduce recursion to students who have never worked with it. While I see the values of tracing recursive calls I think it can be misleading from one of the keys of recursion - the base cases. I don't know many of my peers in this course, but overhearing others work through some of the recursion exercises in my lab I heard people getting hung up on going step by step through what was taking place in their recursive calls, instead of focusing on whether or not the logic they used to construct their base cases was sound. Writing accurate docstring as a template for your recursive call and implementing based solely on those ideas can often bring you close (or all the way) to a perfectly implemented method.
Another point of emphasis I've noticed in this course that has puzzled me slightly has been the focus on writing (relatively) complicated list comprehensions in order to produce more compact code. While I see the value in comprehensions, I've seen one or two examples of students trying to write an entire method in a single, complex comprehension. One line solutions to a problem can be incredibly satisfying, but in my opinion can often hinder the readability of your code. I much prefer if my partner produces 5 or 6 lines of clean code that is more readable, intuitive, and produces an equally correct solution. Maybe that's just me though.
All in all the semester is winding down. I'm looking forward to a relatively low-key exam period (only three exams) and starting the summer off on a positive note.
Thursday, 31 March 2016
Wednesday, 23 March 2016
Week 10
Finally submitted A2. There were a few incredibly frustrating bugs I had to deal with for this assignment, one of which plagued me for upwards of 5 hours.
In trying to develop extensions for Grid Peg Solitaire I was accidentally making changes to the state of the puzzle, instead of creating new Puzzle objects and returning a list of said objects. I was puzzled (no pun intended), as I wasn't actively adjusting any of the attributes of self in any of my helper methods, but without fail in each iteration of one of my loops the board state would be altered. I eventually found out that when accessing nested lists, Python only supplies a copy of the first level of depth of the list, every subsequent sub-list is aliased (not copied) which is why I was altering the board state of self. Thankfully as soon as I made the necessary adjustments to my methods everything ran exactly as expected.
The second problem (it wasn't even really a bug) I encountered was slightly less frustrating, as it took a lot less time (and tracing) to correct. My solves were taking a very long time to run, especially for some of the larger puzzles available for testing. I took the advice of some of my peers on Piazza and switched the data structure used for storing already-visited board states to a set. I also realized what a potential use for __repr__ might be (comparing string representations of the current state and all the states stored in the aforementioned set) and so implemented that for my four puzzles. After making this switch my solves took SIGNIFICANTLY less time. A satisfying adjustment.
All in all the assignment took less time than I imagined it might (thankfully, as my being sick for two weeks leading up to it only allowed me about a day to really work on it). I'm expecting a very positive result. Hopefully I'm not disappointed.
In trying to develop extensions for Grid Peg Solitaire I was accidentally making changes to the state of the puzzle, instead of creating new Puzzle objects and returning a list of said objects. I was puzzled (no pun intended), as I wasn't actively adjusting any of the attributes of self in any of my helper methods, but without fail in each iteration of one of my loops the board state would be altered. I eventually found out that when accessing nested lists, Python only supplies a copy of the first level of depth of the list, every subsequent sub-list is aliased (not copied) which is why I was altering the board state of self. Thankfully as soon as I made the necessary adjustments to my methods everything ran exactly as expected.
The second problem (it wasn't even really a bug) I encountered was slightly less frustrating, as it took a lot less time (and tracing) to correct. My solves were taking a very long time to run, especially for some of the larger puzzles available for testing. I took the advice of some of my peers on Piazza and switched the data structure used for storing already-visited board states to a set. I also realized what a potential use for __repr__ might be (comparing string representations of the current state and all the states stored in the aforementioned set) and so implemented that for my four puzzles. After making this switch my solves took SIGNIFICANTLY less time. A satisfying adjustment.
All in all the assignment took less time than I imagined it might (thankfully, as my being sick for two weeks leading up to it only allowed me about a day to really work on it). I'm expecting a very positive result. Hopefully I'm not disappointed.
Wednesday, 16 March 2016
Week 9
Just got out of the second midterm. I feel like it went pretty well, a good thing as I was one of the students who couldn't write the first midterm due to the fire alarm incident. I don't think I made any mistakes in the midterm. I finished in about 20 minutes so I had a lot of time to look over my solutions, and am pretty confident. Unfortunately, because of the nature of the formula that my test 1 grade is being determined by, I need to hope that everyone else didn't find the midterm as straightforward as I did. The recursion tracing question contained possibly the only curveball in the entire midterm in my opinion, but once the second parameter of print was clarified it proved just as simple as a recursion tracing problem might be expected to be.
As I'm not able to attend lectures in this course due to a scheduling conflict, I was a bit concerned that the emphasis on list comprehensions in this course might leak into a term test question. I'm confident in my ability to read comprehensions, but as I don't really see the point in trading off readability for compression I don't often practice writing them. Thankfully we weren't evaluated on them, and until we receive our results I'll remain very optimistic.
As I'm not able to attend lectures in this course due to a scheduling conflict, I was a bit concerned that the emphasis on list comprehensions in this course might leak into a term test question. I'm confident in my ability to read comprehensions, but as I don't really see the point in trading off readability for compression I don't often practice writing them. Thankfully we weren't evaluated on them, and until we receive our results I'll remain very optimistic.
Monday, 14 March 2016
Week 8 - A Bit Behind Schedule
It's been a hectic 2 weeks for me so hopefully my lateness is excused.
Last weeks labs were the only real recent connection I've had to 148 material and I found the lab #7 exercise relatively straight forward. Without working on it ahead of time at all I was able to finish the lab exercise and almost all of the additional exercises. The quiz from the lab was also relatively simple, so hopefully I locked up the full 2 marks. I'm going to start working on Assignment 2 today, and since I accidentally didn't post my Week 6 blog, I'm going to try and include a few extra blogs on my process in the second Assignment.
Last weeks labs were the only real recent connection I've had to 148 material and I found the lab #7 exercise relatively straight forward. Without working on it ahead of time at all I was able to finish the lab exercise and almost all of the additional exercises. The quiz from the lab was also relatively simple, so hopefully I locked up the full 2 marks. I'm going to start working on Assignment 2 today, and since I accidentally didn't post my Week 6 blog, I'm going to try and include a few extra blogs on my process in the second Assignment.
Thursday, 3 March 2016
Week 7 - Recursion
I've been familiar with recursion since early last year, and although it doesn't often come up in my work, it is incredibly satisfying when it does. Of all concepts one can learn early in their programming education/career, recursion opens up not only countless possibilities with respect to various recursive data structures, but also can facilitate some unimaginably elegant solutions.
Personally, when I first learned recursion it seemed almost magical. I was taught to never try and trace the program, but instead rely on constructing robust base cases, and sound logic in making the recursive calls. The end result of these two major keys (anotha one), is code that is concise, elegant, and WORKS (the latter of the three often occurring to your own pleasant surprise). The magic hasn't faded to date.
Successfully implementing some recursive code is not only very satisfying, but it also gradually cements your understanding of the concept. Mastering recursion can be a powerful milestone in becoming a more efficient and effective programmer.
Personally, when I first learned recursion it seemed almost magical. I was taught to never try and trace the program, but instead rely on constructing robust base cases, and sound logic in making the recursive calls. The end result of these two major keys (anotha one), is code that is concise, elegant, and WORKS (the latter of the three often occurring to your own pleasant surprise). The magic hasn't faded to date.
Successfully implementing some recursive code is not only very satisfying, but it also gradually cements your understanding of the concept. Mastering recursion can be a powerful milestone in becoming a more efficient and effective programmer.
Subscribe to:
Posts (Atom)