0

OK to be short =)

I'm noob yes. -.- but I'm convinced i don't need to learn everything.. and that a specific field of knowledge suited to my project may save me time..? I'm going to build a game that i have designed but not begun constructing. I'm going to learn everything i need to to get my project finished.

however to save time...

I'm using python the game needs only to reference locations on a grid with values: so a green 'pine tree' square = *information *values = tree type / tree's hardness / tree's life ect...

I am perhaps wrong in the assumption there are no objects needed? should i focus all my time on learning how to use the dictionary's function.. what is the most efficient coding for a grid based tile game that simulates change per turn.

So that; a blue square spreads according to sets of rules and according to the adjacent tiles at the end of a turn. And these tiles have values attached...? even just the name of the best feasible technique... i can learn how to do it once i know what i need to learn...

agf
  • 171,228
  • 44
  • 289
  • 238
Wylder
  • 11
  • 2
  • 1
    Its a bit difficult to understand. Do you want to use a `dict` to simulate objects and its fields (i.e. do you plan using `mydict[field]` instead of `myobject.field`? If so, better switch to the latter (using objects). – phimuemue Aug 13 '11 at 09:39
  • Although the question is somewhat poorly phrased, I think it's a good one and should stay open -- why do we need to learn the whole language? Why are objects important? – agf Aug 13 '11 at 10:03
  • 2
    I don't think it would make much sense to plan in advance what to learn from the language. Just start with your project, taking your ideas to code, having a couple of books at hand (diveintopython.org is an excellent -and free- one to start with), and learning whatever you need to solve your current problem/idea. If you are new to programming you will surely rewrite your code multiple times as you learn better ways, but I don't think that is a bad thing. – AJJ Aug 13 '11 at 10:15
  • @Wylder I won't answer your question in order to save time, because I am in a big hurry to play a game – eyquem Aug 13 '11 at 10:20
  • lol i reckon this proves i know nothing and i need to go practice – Wylder Aug 14 '11 at 02:32

2 Answers2

9

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.

agf
  • 171,228
  • 44
  • 289
  • 238
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.

RoundTower
  • 899
  • 5
  • 9