[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



> Many of my variables' names are re-stating the exact value they hold, so I
> rarely have any confliction with names:
>
> filename_of_current_level = 'desert.txt'
> Font__New_Times_Roman_size_20 = ...
> pi_divided_by_180 = math.pi() / 180
> etc.
>
> The names are just according to what values they hold which-- are all
> unique anyways!
> And when the number of variables start reaching the hundreds, it just gets
> really crazy with "global this global that" ALL OVER my code, again and
> again . . .
> : (

Two questions: first, what's with the excessively long names, and second, why is it so important for these to be stored as global variables? I have a hunch that a LOT of your global variables would be much better off in objects.

> If I use dictionaries, I must type:  "d['whatever']" for ALL my game variables!!!
> Same with using classes--  "c.whatever"
>
> It's like    "pygame.draw.line()"   instead of just: "DRAW_LINE()"
>
> or like: "random.random()"   instead of just:
> "RANDOM_NUMBER_BETWEEN_0_AND_1()"
>
> "Pygame dot draw dot line" (It sounds so lame too) 
>
>
> Arrg!! It's like driving me crazy!
> . . . 
> sigh
> . . .
>
> Sorry guys, I'm just feeling very frustrated with all these crazy
> programming conventions.

You would rather deal with a cluttered mess of global variables than organize them into classes and namespaces, just because you don't like to have to put the namespace or object name before the variable you're referencing?

Huh?

Do whatever you want, but seriously, this is just a silly complaint and tells me you haven't even TRIED to use object-oriented programming.

> (PS in case you haven't already, you can check out my really cool
> physics program in the Python Draw docs! I'm not a "troll" I was just
> having way too much fun. lol)

I looked at it, and like I expected, it was a terrible mess, not a good example of whatever it was attempting to do.

Out of curiosity, how long have you been programming, and what languages have you used?