Wednesday 26 March 2014

Sorting and Efficiency

Efficiency does not only streamline the process that the code is running under, it also encourages efficient thinking and planning before the actual implementation of the code. Efficiency may seem like an unnecessary concern at the moment in lower level courses with short functions, but when those functions are part of a much greater whole later on, it will become important to optimize everything. Sorting is a step towards efficient code, as like other concepts covered in CSC148 such as object oriented programming serving as a template for further development in code, sorting is a process to serve as preparation for other functions such as searching within the sorted object.

Bubble sort runs through the entire list in pairs and exchanges the position of the elements if the first element is greater than the second in the pair. It is inefficient as resources will need to be allotted for the exchange process. Selection sort is more efficient as it does not make any changes to the existing list during its run through and one exchange is made per run, making the runtime of the process predictable instead of dependent on the variables in the list. Insertion sort seems more complicated, but due to nothing being swapped, only shifted, the process runs well. Shell sort is strange, using insertion (once again as a template) to sort the elements in between specified gaps, pre-sorting to make the final sorting easier. Initially, I thought that merge sort required swapping during the combination, but it seems that the elements in both lists are combined and sorted into a new list and is more efficient as nothing is moving around. I feel that quicksort is similar to bubble sort in that its efficiency depends too much on the list and is thus unreliable while also being a little more complex to understand than merge sort. Timsort, while also dependent on the chance of order in the data itself, makes up for it by being adaptive in being able to make itself easier to sort using sorting methods and finding efficient merges instead of forcing the sort regardless of circumstance.

Saturday 15 March 2014

Regex

Assignment 2 part 1 was quickly gotten over with. Despite its relative ease of coding, I think I was not as thorough as I thought I was in the documentation. I had not provided examples for the children classes of the primary regex class as I inherited most of the methods of the parent class. However, just like providing background information in an essay, it is important to provide examples in function documentation even though the target audience would surely be able to understand your work without it. It's better to provide more information than needed than to lose marks for under providing.

Part 2 is more complex than part 1, requiring recursive thinking to get the job done. My code so far converts the regex string provided into a treelist before anything else. Is_regex has also been coded, though some frustration was had to recognize regexes containing the '*' character in its various positions. The permutations should be easy since is_regex is done as the code for permutations has been covered in lecture, and building the regex tree should not be a problem. What's hard is going to be matching the string with the node.

Tuesday 11 March 2014

Praise Isinstance

Isinstance is ridiculously useful. Despite being somewhat awkward to type (isisntnance?), I find this built-in function to form the backbone of many assignments. Recently, I discovered that isinstance worked with inheritance, allowing a child class to be identified as its parent. This was rather useful in sifting out exceptions and bad inputs for the regex assignment as well as determining whether the inputs were regexes or not. After getting to know how isinstance worked, list comprehensions also became more intuitive as it is one isinstance's natural habitats.
Still need to learn how any() and all() works in recursive structures and how to return multiple values from a list comprehension.

Wednesday 5 March 2014

Recursion

Recursion is when a function, under certain circumstances, calls itself to make new evaluations based on the variables obtained during the running of the function. Initially, I had the impression that this was similar to nested while loops, but it seems that while those progress in a relatively straightforward manner, recursion dances forwards and backwards before reaching the finish line. It makes me feel as though I was watching a science fiction movie about time-travel with mind boggling timelines and paradoxes.
The short assignments were simple to understand. It doesn't take much brainpower to understand the recursion going on in finding the number of nested objects in a list, but I feel that there was an enormous gap between those simple tasks to the cheese tower assignment. I've been told to not think about the underlying processing of the functions too much, but I believe I did anyway and ended up confusing myself instead. I couldn't accept that if it works, it works. Maybe it's a good trait to have, but not when it costs me marks. I'll look around for more recursion problems to do, it should make sense eventually, just like math equations.
I hate to be afraid of recursion. Maybe psychologists should classify recursionophobia as a legitimate condition.

Saturday 15 February 2014

Crumbling Cheese Tower

Man, that assignment was rough. The recursion really boggled my mind and I over thought way too much when it was in fact rather simple. Every night I would think I figured something out just to have my hopes evaporate the next day as I realize that the code only works to a certain extent. I read through some slogs in hope for a stray tip, but everyone concealed the meat of the information really well (to my dismay).
I went to a few help sessions; the TAs and even students there really helped me out. The Bahen building is really nice, even though I didn't realize how much I got used to the constant barrage of music in my own faculty before entering into the relatively quiet compsci building. The majority of the computers in the music faculty might as well have negative ram given how quickly they seize up.
Now, onwards to the next assignment. >_>

Friday 31 January 2014

Excepting, Inheriting, Composing, Recursing

Exceptions

Exceptions seem to be solely for the convenience of the users, allowing them to know that something is wrong with their input. It's something that requires some out of the box thinking on the part of the programmer to correctly predict what kind of inputs users are likely to make as the programmer's testing of the program usually involve correct parameters.

Inheritance & Composition

This is quite straightforward. Inheritance allows one to append their own methods to existing classes, update the obsolete methods of the old classes, etc while making citation of non-original material a breeze. I believe that composition is like using the import function while inheritance actively overwrites the parent functions unless super() is called. One of the keystones of object-oriented programming as it gets rid of excess code and serves as a basis for further development of the program.

Recursion

I think this is a topic that's hard to visualize without it written down step by step. Everything is done almost backwards as you start from the inside and progress outwards. The examples and exercises themselves haven't been too difficult to comprehend just yet, but I feel that it will become mind boggling with real world examples or something similar.



Thursday 23 January 2014

The Objects of the Orient(?)

After a 2 year hiatus from courses that require logic during my study at the Faculty of Music, the process of picking up programming has ranged from simple to excruciating. I can almost feel the rusty logic gears in my brain, where fungi most likely has long been cultivating, struggling to restart the turning. However, I forgot how satisfying it is to solve a logical puzzle - burning the midnight oil to finish off an assignment I couldn't get my head around, having everything click into place and finally getting the program running is simply exhilarating to a newbie programmer (until the crushing despair of realizing I missed an important instruction...).

Object-Oriented Programming

Object-oriented programming, from what I understand, is similar to having a template at hand so that a programmer can create things particular to that template easily and efficiently, doing some work now to save a whole lot of repetitiveness down the line. This is similar to the audio engineering course I'm taking, where a template contains the preset hookups to the pre-amp, reverberation units, the microphones, and others, to save the time otherwise taken up by the setup that will inevitably irritate the grouchy musicians you are recording. Many programs has been using such frameworks for quite a while now. Office programs provide templates, musical notation programs let you choose your favourite fancy and stylistic note heads and clefs, etc. Maybe the Classes developed early on in this course will be used in later assignments?



I want to make the blog pretty pls instruct much appreciate.