Making a Program the Right Way: Organizational Skills

Would you like to see more in this thread?

  • Yes.
  • No.
  • It was useful, but it’s gone on long enough.
  • This wasn’t what I was searching for.

0 voters

Hello to everyone who is part of this great community. I’ve just completed my first book on Python and a few chapters into my second one. I’m planning to begin my own project, shortly. I’d like to get inside the programmers’ mind and figure out a good way to build quickly but remain organized. It doesn’t make sense to me to import everything, then delete what is unneeded. Equally, it makes no sense to me to take every import command and immediately move it to the top of the program (though it makes more sense than the first method).
I’m not sure if I should create many small scripts, or one big one. Should I keep my “big” script open and just edit-cut/copy-paste all the code I like or need to complete the big script? Should I make a separate .py file for each level? Or, should I make .pyc files, then make a small .py file to start the game and reference the .pyc files? ^^

Can someone give me some tips on how a project looks? What are the steps in creating something really wonderful? Is it possible to apprentice under someone for free, as this is an open-source community? If so, how would I do that? I want to learn to be a great coder for games, but I need to figure out how to do it in an organized, smooth, quick, productive fashion. I honestly feel I might need to work under someone to pull that off. Please prove me wrong. Or, if you will participate in my thread, please help me compile some resources for people who share my passion for this awesome project, so other people will have it a little easier than we do. ^^ Right now, we have a pipeline forum. It is really nice. Let’s dumb it down a little more. ^^

I have view a lot of tutorials and I must tell you the best way of a tutorial is to be as short as possible targeting only what is needed for that step. Of course there are cases where a line alone will not work (ex. light cannot be seen without objects on which to reflect) so it may be right to import stuff from the previous projects (in this case object loadings).
As for pyc’s and py’s I suggest pyc’s because you will learn all this short stuff which might look cool but as soon as a viewer is trying to make a program all that stuff together (some repetitive) might overload the program. SO in my opinion a complicated program’s (especially a game) core should only load the external modules.

SO a logical game’s core for example should only have:(logical design)

Begin -> Externals importing -> GUI -> Game -> Exit

Where GUI means a class/function which handles all GUI’s based on situation. Game is the real game. And Exit is only a function which terminates the whole thing. So this program is only calling them, these modules are interpreted somewhere else.

And that modules should handle each game part, this way everything will be organised and clear. But these is only my opinion!

Great reply and good luck with your first gaming project. I think that you’re really onto something. “The Way of the Programmer” says to take as little as needed from outside programs, also. So, you are probably an experienced programmer to say something like that.
Let’s keep this thread going, guys. We need more as many replies as we can generate. This is a really important thread. :slight_smile:

Hi everyone, I figured I’d keep posting here for others who were interested in this discussion. I found out about something called “flow of execution” in chapter 3 of “Think Python”. Apparently, when reading Python code it is best to read in the flow of execution. To learn more about this, I recommend reading “Think Python”, or at least Ch. 3. It seems that the Python community regularly performs upkeep on this most excellent literary masterpiece. It is also freely available, online. Check your google :unamused: .

I have probably less than zero experience with panda so far but here are two things that work for me:

do it once sloppy, then do it again better, a la “Xtreme Programming”. Works great in a language like python. Often this means start by making one big script as you’re figuring things out, then throw the whole thing out and start it over as a module or modules with individual scripts (for me that’s usually in the manner of java or c++; habit) once you know how you want to work cleanly.

for me a good tutorial is one that’s clear and focused on a particular task. I like tutorials that go for verbosity and clarity over clever tricks. Often there’s a long way and a short way to do something, but if the short way is really abstract it can get in the way of understanding what’s going on.

Flow of execution is itself maybe a good example. A lot of the time, for a well-written program, you’re going to want to make use of lots of callbacks, handler functions, event queues and listeners, etc. Another way to go might be to use a core monolithic event loop with condition tests, but that’s way less efficient and less scalable, right? But it’s also much easier to understand, because you can follow the path of execution easier. So my preference would be to do the long way first, then demonstrate why that creates problems, and then introduce the clever way.

Like copying and pasting a line of code 400 times before learning about the ‘for’ loop.

Hello, I’ve been doing more research on this topic, because I posted it, right? :unamused: Gotta keep it up. I found a keyword for all those interested in this topic: “Development plan / development planning”. It’s great for people making tutorials, also, I think, because if you follow a development plan in your tutorials, you will be able to show a bunch of newbs how to make their own programs, rather than what the code looks like for a completed program. Of course, you can build a program and say, “Well, this makes a circle,” But then you’re just throwing the newb a fish. Wouldn’t you rather teach the newb HOW to fish? :smiling_imp:

So, in the next paragraph I’ll describe what I’ve found on development planning and how to go about making your own programs. Also, I think it’s great for tutorials. If you are an experienced programmer, please remember to dumb down tutorials and show us newbs your development plans with your step-by-step guides to making most excellent games.

Development planning:
First, you want to make a very general program that does what needs to be done, without any functions. It should sort of run by itself. It should do a part of what needs to be done in the grand scheme of things. For example, if you want to make a player jump up and down, just make a player jump up and down. Don’t do a block like

def jump(player, force, ceiling, aircontrol)

and go on with all the keys or whatever. Instead, just write:

jp(p, 6.4, 10, 2)

Or whatever, to make sure that your character jumps and test some values. Now we’re having some fun. :blush:

Second, encapsulate your program into the most basic function possible. For example:

def jump()
    jp(p, 7, ceiling, 2) #this is a jump value that I like, ceiling is a global variable that changes based on where the character is located
    self.player1.actorInterval('jump', startFrame = 1, endFrame = 7), #jumping up for 10 frames
    Func(self.checkJump, 2) #checks if the character bumped his head on the ceiling (he didn't)
    self.player1.actorInterval('jump', startFrame = 8, endFrame = 14)) #falling for 7 frames

Now your function has a name and an animation. That’s nice, isn’t it? Sometimes, all your function needs is a name and an animation. If what you have defined is always going to do the same thing, all you need is a function. Functions are easy to remember, and you can use them for keypresses or whatever. If there’s a low ceiling, though, the character is going to bump his head! :astonished:

So, next you want to go through “generalization”. You basically add parameters to the function. Usually, you need to go through this so you can use the jump function for different players in conjunction with animations, and you can change how high each character jumps. Stuff like that.

def jump(player, height, ceiling, aircontrol)
    if height >= ceiling 
        height = ceiling 
    if height == ceiling
        self.checkJump = 1
    if height < ceiling
        self.checkJump = 2
    jp(player, height, ceiling, aircontrol) 
    self.player.actorInterval('jump', startFrame = 1, endFrame = height), #jumping up for height frames
    Func(self.checkJump, a) #checks if the character bumped his head on the ceiling, if he did then self.checkJump should change to 1
    if self.checkJump = 2
        self.player1.actorInterval('jump', startFrame = height, endFrame = height * 2) #falling to the floor
    if self.checkJump = 1
        self.player1.actorInterval('bump', startFrame = 1, endFrame = 4)
        self.player1.actorInterval('jump', startFrame = height - 4, endFrame= (height * 2) - 4))

jump(sonic, height=7, ceiling, aircontrol=4) #I'm adding keyword arguments, so you guys remember.
jump(tails, height=12, ceiling, aircontrol=6) #Arguments such as 12 and 6 work the same as height=12 and aircontrol=6, but keyword arguments are useful reminders.

Sorry, it is a little generic. ^^

The hint that I got for the generalization step that helped me the most was: ‘If your comments explain how something happens, rather than what is happening, it’s not general enough.’

So then, you just repeat and debug. My code probably needs debugging, for example. I haven’t tested it. I just used it as an example, so that you guys could see the process. It keeps a steady flow of work coming out of you, which is really fantastic.
The final step is to improve your program. This is called “refactoring”. Even the hottest programs designed by the best programmers can often be refactored. There are often generalizations that they needed which you won’t be needing, or you might want to add a new function definition that uses an old function. It’s a great way to learn and study things… to refactor.

Anyway, this is a development plan. I am still looking for more advice, so all you veterans jump in and give us some advice. I’ll try to post some more reliable codes and tutorials, soon. Okay? Peace!