Friday, 31 January 2014

Object-Oriented Programming

Like Java, Python is an object-oriented language, which allows the creation of abstract, user-defined data types to store information and useful built-in functions. Being able to define concepts, name them, and define the information stored within them helps a lot with making code easier to read and understand, which in turn will help the programmer himself understand his own code by defining it in his own terms.

This allows the existence of more complicated programs in the same way that going to school makes you smarter. Teachers at school may define a complicated theory or mathematical concept by explaining the reasoning behind them in detail, then they will condense all of that reason under a name or formula. Taking all the reasoning behind the theory and condensing it under one name allows you to 'chunk' it into a piece of data that can be operated on - because a name will take much less of your attention span to think about than a full theory, you free up more of your mind to operate on that name in a broader context, which allows you to produce more complicated ideas.

Object-oriented code will look much the same way. Instead of having one gigantic block of text splatted onto one text file, you can now package smaller data types into single words or names, that are then associated with an underlying data type. For example, instead of looking at the size, speed, color, fuel capacities, models, etc. of each car laid out on a gigantic amalgamation text on a road, you may look at a road with many 'car' objects racing along, and then look specifically at one 'car' object to find all the data associated with it.

It is this packaging of complicated data types under a name, or 'object,' that makes object-oriented programming so powerful.

No comments:

Post a Comment