Monday, 16 February 2015

Into the Forest

I think I'm slowly getting the hang of recursion. Writing it doesn't take quite as long as before and my head can slowly wrap around the logic of using the function within itself. However, a new problem was introduced: Trees. 

I'm not going to lie, I fell asleep for most of the class on the topic of trees. To no surprise, the notion of how trees were set up made no sense until I actually played around with the code. I now understand that each child is its own tree, and calling upon a tree's children creates a list of the names of the trees that can be called upon, rather than the values of the children themselves. After learning this, writing recursive code through trees became easier, but it still took sometime. I particularly had trouble with code that had to analyze every single element in a branch rather than just the leaves, due to having to add on an extra section on top of the for loop. 

I can see how trees can be useful, for creating programs and menus where clicking one item leads to an array of other options, with no overlap between them. However, their usefulness is limited if you need an option that can be accessed through multiple means. Maybe you could use multiple separate trees in that case? 

(-o-o-)

Sunday, 1 February 2015

First Impressions

One word: Recursion. Holy shit. Stuff messes with my head in loops like no other. Writing out a recursion flow chart thingy isn't too bad with the examples and all. Figuring out a recursion code without the docstring is a bit trickier, but writing recursion code itself is the stuff of nightmares. One trick I've found so far is to always keep in mind the original goal, as a function pertaining to counting or finding out the largest number will always have to come up. As usual, I suppose more practice should do the trick. If you have any other tricks...feel free to share them for the greater good of my sanity. 

Other than recursion, the concepts in python haven't been too bad. Classes are okay, although I'm still not entirely too sure how to use them very effectively, particularly when it comes to assigning __str__ and __repr__. Sub-classes are neat, but I feel like I should probably be writing more code in the super-class and then inheriting it. Oh well! 

Coding's been pretty fun so far, though admittedly it takes up time. At least it's rewarding when the code finally runs! 

(-o-o-)