Do I Need To Learn About Objects, Or Can I Save Time And Just Learn Dictionaries?
Solution 1:
Any Python project of any size will become unmanageable without objects.
Is it possible to use modules as your objects instead of classes? Yes, if you really want to. (In Python, a module is what you call a single file.)
However, even if you aren't creating user-defined classes, you still need to learn how to use objects.
Why? Because everything is an object in Python. You need to at least know how to use objects to understand how to use the built in types and functions in Python.
In Python, dictionaries are very important to how things are implemented internally, so your intuition that dictionaries would be an alternative is good.
But dictionaries are objects too, so you'd still have to learn to use objects, without getting the benefit of their ease of use for many things vs. a plain dictionary.
My advice? Do a Python tutorial (or three). The whole thing. Even the parts on networking, or whatever else you don't think you'll be using. You'll learn things about the language that you'll end up using later in ways you'd never anticipate.
Do you need to learn about metaclasses? No. Multiprocessing? No. But you need to learn all of the core language features, and classes and object oriented programming are the core language feature. It's so central to nearly all modern languages that people don't even mention it any more.
Solution 2:
I disagree that you should learn everything up front. I think it's just fine to learn parts of the language only as and when you need them.
But in Python you can't really avoid learning something about objects. Everything is an object. A string
or an int
or any other data type is an object. More relevantly, anything you import is an object. You won't be able to get very far in any project without importing existing features at some point, so you will have to work with an object-oriented interface.
So could you get away without learning how to define your own class of objects? In principle yes. But to understand the basics is trivial, and then you can learn the rest as you need it.
Class MyObject(object):
pass
Easy to learn! Now you have a custom type (a class) of object. You can create an actual object by calling m = MyObject()
. This class provides almost exactly the same functionality as a dictionary. But you can start with this and then, when you need it, you can add more functionality (inheritance, methods, ...). If you start with a dictionary when an object is appropriate, you will just paint yourself into a corner.
Post a Comment for "Do I Need To Learn About Objects, Or Can I Save Time And Just Learn Dictionaries?"