Can a low-level programmer learn OOP?

matt westerburg westymatt at gmail.com
Fri Jul 13 17:15:03 EDT 2007


On 7/13/07, matt westerburg <westymatt at gmail.com> wrote:
>
> I also come from a low level background (assembly and c) and I struggled
> with object oriented programming.  People talk about procedural languages or
> designs and object oriented languages or designs.  But after the interpreter
> or compiler runs the byte or machine code is procedural always.  Object
> oriented code changes the structure of how the code is designed.  Its merely
> a convenient way to logically group similar functions and variables.  This
> is done in C via header and implementation files.  Classes provide a simple
> syntax normally for associating many variables and functions inside which
> generally achieve a common goal.  This class becomes an object that is
> manipulatable.
>
> For example one might want to make a class to centralize their file
> operations in a particular program.  For instance a logger class for keeping
> track of execution.
>
> class logger:
>    file = None
>    def __init__(self):
>        #code first executed on instantiation of the object
>        #you must make an instance of a class otherwise its a template
>        file = open('programx.log', 'w')
>
>    def write_to_log(self, message):
>        #self is the instance of the class you made its used to internally
> reference those variables contained within
>        #
>        self.file.write(message)
>    def close_log(self):
>        self.file.close()
>
> The class allows for internal referencing of variables so that the
> variables are global to all methods or functions.  Like the for example the
> file handle to write to.
>
> OOP is merely an organizational structure that can only be grasped
> appropriately by repeated use.
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070713/149de585/attachment.html>


More information about the Python-list mailing list