Consequently, I ended up doing a lot of at-home reading and research. First thing I realized: the "Code Like a Pythonista" link on the course website is not useful unless you like to torture yourself. In general, lengthy readings do nothing for my learning in CS. I've discovered that I just have to jump right into trying to solve a problem, and then go to the readings afterwards if I have difficulty articulating my ideas to myself. (I found that http://tomayko.com/writings/getters-setters-fuxors, which the prof posted online, was very helpful though. Scroll until you reach the section on getters in setters in Python, however.)
A major aspect in computer science is object oriented programming, which is basically creating classes in code that represent "objects" which can have methods performed on them. Objects have attributes which are what allow a programmer to manipulate said object.
In computer programming, somebody who knows how to find their way into the guts of a program has all the power. Consequently, the original coder uses property control to protect their ideas and intentions. A analogy would be something like the mail-slot in a door. Envelopes can be slipped in, but from the outside it is impossible to retrieve and/or change the mail.
Property control is somewhat the same. As a coder, you make it so that once an object's attributes are set, they cannot be changed and only viewed. Furthermore, they can be read without having to use the polite underscore prefix, for example: "attribute_name" instead of "_attribute_name."
This is thanks to getters and setters. Although I won't get into the nitty-gritty of coding getters and setters, a getter is basically a function that returns the value of said attribute. A setter, on the other hand, is what the program looks at when someone tries to set an attribute. If the attribute has yet to be determined, the setter allows an outsider to do so. However, if the attribute value already exists, the program firmly rejects any changes.
While I see the important of property control, oddly enough we seem to have completely ignored it after learning it. Perhaps it's more important in actual client code, rather than assignments we submit for CSC148?
No comments:
Post a Comment