понедельник, 6 апреля 2015 г.

Recursive functions - revisited

Despite the fact that last 2 assignments involved writing and optimizing deeply recursive functions, I don't think I'm as comfortable with recursion as I can be. Of course, I understand how they work and how they're created, the concept of looking at base cases and calling recursion in all other cases helps a lot, but the functionality - where to add something to the output, where to modify some other parameters - is still not as easy for me as it could potentially be. Again, writing Minimax for 4 strategies helped a lot, but I think that my understanding of recursive functions can be further improved. However, the problems that I'd been experiencing previously (where a recursive function should call itself, etc.) are now gone, but modifying the output so that the output from the "root" function depends on outputs from all "node" functions can still be tricky at times. I believe, practising writing recursive functions can help me understand this part a great deal - at least, I feel that there've been much improvement since I first encountered recursive functions. I believe that I've developed some sort of "feeling" for recursion so that the whole concept is not as alien and "technical" as it used to be. In fact, recursion is itself a simple concept, but not always intuitively understandable, as it's farther from real-life ideas that we accustomed to in CSC108.
Anyway, now that I'm familiar with recursion, a whole new field of exciting opportunities is now open to me, as many more types of data can be traversed and/or operated upon using recursion. I haven't tried writing Minimax not using recursion, and something prompts me that it's not practically feasible. 

понедельник, 2 марта 2015 г.

Recursion - to be graded (+ previous post)

Since recursive CPU strategy was the only option for assignment 1, I had a couple of nights of practice with writing it. Over time, I started to notice that the idea of recursion was becoming more and more natural, but plugging in the functionality (where to add, where to return, etc.) is still a little bit more difficult than any other part of the process. I think this can be expected - if a function creates numerous '"daughter functions", keeping track of your output is supposed to be slightly harder than usual.
Overall, I find in-class exercises (trees and functions for them, for example) and labs very helpful. I wish I could spend more time to practise computer science, but being a 2nd-year in an intensive specialist program chews all your time up. I can definitively say that I enjoyed writing the code for Assignment 2, however, there was one technical complication that was drawing too much attention first, so I couldn't think about how to put together the CPU strategy as much as I wanted. Nevertheless, now that I submitted all files and I'm satisfied with how my code works (not with the CPU time that the strategy takes, however), I can spend some time describing my experience with it, and that's what I attempted to do hereby.

понедельник, 23 февраля 2015 г.

"OOP" or "How ++ can matter"

Well, Python has OOP in it from the beginning, so let's forget the ++. Object-oriented programming is the topic of many debates, which are not the main objective of our (students) learning, so we leave those for experts and proceed with given: OOP can help (and/or allow) do things in a better, more understandable, more efficient way. People who've had some programming experience always mention OOP in a context that it is the proper, sterling way to code, which it, in many cases, indeed is. When I was working on assignment №1, I wasn't thinking how I could implement that without OOP, now that I think about it, it seems not very feasible, at least, reasonably: I'm pretty sure you can find a person who can write the same thing in ASM or in machine code, but readability and ease of use will, of course suffer. In other words, why complicate if you can simplify? Making use of "objects" which have "properties", "methods" and "attributes" - looks like a very vague idea, but you can specify each subtle aspect of the object you've created - what it looks like if you call print on it, what defines the object, how it interacts with other objects and so on. In my opinion, OOP is the further development of the idea of a variable: variables can have text and/or numbers in them, or lists of the above, can be manipulated, created, and so on. Now our "variable" (an object of type class) can itself interact using "smaller" interactions as building bricks, the "smaller" interactions being the Python itself. I'm pretty sure that I'm far from describing OOP in the best manner possible, but this is how I see it - creating building blocks that have many functions besides being a building block, just like a Swiss army knife which you tailor according to your needs.
However, there's some conventionality and formality that I don't seem to get: why would we be using a method placeholder that raises the exception when we can implement basics in it and use them later on in subclasses? Maybe it's that thing that one should remember and do, but I always try to find a reasoning, and, so far, I haven't been able to find one.

среда, 18 февраля 2015 г.

Recursion: first look

This time I'm describing my experience with recursive functions: writing, tracing in order, finding out what a function does. Generally, recursion is considered as a concept that is difficult to understand. However, this is not exactly true. It is true that "thinking recursively" is a skill that has to be practiced a lot in order to be mastered, but it does not involve anything beyond common sense and basic knowledge of programming. In short, recursion is an algorithm whereby a function calls itself. Once you're comfortable with how a function "sees" the data tha you pass to it and know what it does with a smallest subunit of data (e.g. a list), you can easily trace a call in order. So, tracing is relatively easy, unlike writing recursive functions. Sometimes it's difficult to find the right place for a recursion statement (i.e. when a function should call itself), sometimes it's challenging to squeeze the actual functionality in (i.e. where the function changes or creates its output). Several times I'd find myself having a function that has recursivity, that goes through the input the right way, but produces no output. Creating a variable that will be able to change itself depending on its value in "daughter" functions - this is what is tricky for me. At least, I don't breeze through this part every time, some functions and algorithms are easier to write than others.
To sum up, the whole concept of recursion is of high importance and can be applied anywhere you need (or don't need, just want) it. Yet, with high importance increased difficulty comes. A bad thing? Expectable, not more than that.

вторник, 3 февраля 2015 г.

First weeks...

So far, my journey to the fascinating world of Python's going fine. It feels that the language can allow you to do lots of things, even shooting yourself in the leg, if you know how to make Python do so. Every object seems to have "hidden" properties that return an error unless you've done something to them to make them work the way you want them to. One good example'd be class method "abstractmethods" - it is in object's dir, but returns an error upon calling help on that. However, this thing can be modified and used the way you want it to. In the context of the course, this is not the most important thing, though.
Recursion, apparently, opens a whole new field in Python. Looks exploitable, however, caution should be used when running some recursion-containing function. Otherwise, you're very likely to run into an infinite loop. Fortunately, this won't be too bad - most CPU's have multiple cores, Pythin uses only 1, so the freeze won't be awful. Moreover, Python seems to have a built-in loop detector, which quits a program if a loop's been run over 300 times.
Messing with attributes of classes and making them inaccessible for your typical user also seems to be a powerful tool, especially for managing objects that are not supposed to be modified. It might be difficult to appreciate usefulness of these small things until you run into a situation where you absolutely have to make use of them. What is knowing a programming language if not knowing small useful things about it?
Looking forward to the upcoming lecture on sorting mechanisms - I'd like to use a faster algorithm in one of the scripts I wrote to make my life easier, as the default, built-in sorting algorithm in Python is extremely slow.

вторник, 20 января 2015 г.

Why CompSci students should (b)log

This week's assignment that requires me to share my opinion on why programmers should be keeping a blog, or a "professional diary", as in Mark Dalrymple's case, made me think that every student, or even a scientist, should be keeping a record of what goes wrong, along with what goes right, in their life as a professional, or a learner. I'm not a CompSci program student, my PoST has much more to deal with molecular biology, however, nowadays computers, and more specifically, programming languages, are used to accomplish a wide variety of tasks, so a widely used in the scientific community and an easily understandable Python is my choice. The reason why I'm making this long-winded intro is as follows: the whole idea for "debugging", as a technique for finding and fixing errors, can be applicable in any area where mistakes and/or errors can occur. Keeping a journal of these errors, and the ways these problems were solved, is a great idea for everyone in their professional endeavor.
During my time as a CSC108 student, I used to keep .py logs every lecture - unfortunately, they don't have any comments, just plain code, but the code was written in a way that illustrated important things about certain functions/methods, etc. In other words, these "logs" illustrate the process of learning and implementing the things you've just learnt, much like a journal. However, this way of recordkeeping has a drawback: it relies too much on your memory, the fact that you'll be able to remember certain small things about an aspect of Python later. A (b)log is an easier way to do this: always accessible (given you have an intact Internet connection), it gives you all the advantages of web technology to help accompany your own ideas so that the latter can be easily reviewed and used as an aid in future projects: I've had too many "what was the small thing I did that made things work" moments to not keep a (b)log, and it's not exclusively about CompSci.
So, taking all above into account, I'd say, not only computer scientists should write, but all scientists (or people who are going to be scentists) should do so.