All my programming experience has been with object-oriented programming, but I don't think I ever understood quite what that meant until learning about objects formally. And I'm sure that I won't have a complete understanding until I gain more experience with other programming paradigms like functional or declarative programming.
In object-oriented programming, different objects of different types interact with each other to store information and solve problems. Objects can be of different types to allow them to be best suited to their specific task. There are types built in to Python already (int, str, bool, etc.) or they can be created using a class.
For example, continuing with my previous discussion of a mental lexicon, we can create a class "Lexicon". To reiterate, our brains' file words into our vocabulary as if they were dictionary entries containing several specific pieces of information, and we refer to this dictionary as our mental lexicon. It will include information like pronunciation, subcategorization (possible complements), and meaning.
So, we know that this class will contain objects that are words, and that these objects will contain pieces of information necessary to be able to understand and use these words grammatically. We will first write an "__init__" method to initialize instances of class lexicon. In this method we can define several necessary parameters to add a word to the lexicon, such as meaning, pronunciation, and category. The "__init__ " method is one of several special class methods that can be accessed using specific syntax, some others are "__eq__", "__repr__", and "__str__".
Now that we have created this specific lexicon class, we can create subclasses that inherit its traits and expand into even more specific functions. For example, we could have a class "Synonyms" that stores alternate meanings of words, or a class "French" to use our lexicon with a different language. These subclasses would not only be able to inherit from the superclass "Lexicon", but would also be able to extend and overwrite its methods. We can see how being able to create such a specific type of object would greatly improve our efficiency in solving problems pertaining to language.
Thursday, February 19, 2015
Friday, February 6, 2015
Tracing Recursion
I found the lab on tracing recursion to be quite confusing. This is probably a result of having been sick during the week's lecture. I read quite a few summaries of recursion from various resources, an felt confident in my understanding of the concept. But when it came to actually tracing function calls, my understanding felt like it was crumbling. I was confused by when to retrace and when to reference a call that I had already traced. And in this confusion I started to question whether I actually understood how recursion worked.
After the lab, I looked over the practice examples and became comfortable with the format. I also talked over some problems with my friends and regained my confidence with recursion. This particular topic seems like something that just requires a little time to wrap your head around, before it can be understood with ease and immediacy. I'm excited to explore the power of recursion in creating efficient solutions to problems. Even the basic example of using recursion to sort a list quickly, got me stoked to get deeper into the topic.
After the lab, I looked over the practice examples and became comfortable with the format. I also talked over some problems with my friends and regained my confidence with recursion. This particular topic seems like something that just requires a little time to wrap your head around, before it can be understood with ease and immediacy. I'm excited to explore the power of recursion in creating efficient solutions to problems. Even the basic example of using recursion to sort a list quickly, got me stoked to get deeper into the topic.
Subscribe to:
Posts (Atom)