[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Declaring variables in function as if at code's line-level



On Mon, Mar 12, 2012 at 12:27:39PM -0700, Brian Brown wrote:
> Matthew N. Brown

I googled. I guess this is yours?

http://pastebin.com/kKXSgw8c

> It's like    "pygame.draw.line()"   instead of just: "DRAW_LINE()"

It's because of fallacies like this that your program would be
completely unmaintainable for anyone other than you.

Classes and modules allow us to break our code into separate concerns
that other programmers can pick up and understand immediately (as can we
when we come back to something having forgotten what we wrote).

They also tend to allow massive amounts of code re-use. If you wrote
only a proper 2D vector class (or downloaded one [1]) I reckon you could
halve the amount of code you had to write for your bouncing balls
program. 

To help you out, here is the A Byte of Python chapter about Object
Oriented Programming (ie. classes):

http://www.swaroopch.com/notes/Python_en:Object_Oriented_Programming

[1] http://www.supereffective.org/pages/Vector-2d-Vector-Library