Help dealing with masses of code

Hi,

I'm well into making 2 games in Corona.

The problem I have is I'm getting overwhelmed with the sheer amount of code in each file. Scrolling up and down to find the function I need to work with is difficult and working with long files of code isn't a lot of fun.

For a Corona newb, modules seem fairly complex, especially when it comes to scope. What do the pros out there do to manage long code? Is there some tool I can buy to help keep organized?

Thanks

Tom

Aha - I have just discovered...

Text Folding!

Lets you expand / hide areas of your code.

BBEdit and TextMate both do this.

Tom

You probably should spend time learning modules. Code folding is just hiding the fact that you're writing one long file.

Yeah, I can't survive without modules. They're really easy to make and it's a real time saver later knowing I can make edits to a function file and have those changes propagate everywhere!

I agree with the other comments, that code-folding is just like sweeping the problem under the rug. It has to be a nightmare trying to locate specific lines of code if you just create a single monolithic file.

The two best resources I've found for breaking my code up were from these two links:

http://developer.anscamobile.com/code/object-oriented-sample-game-framework

here's another slightly different method:

http://www.planetlua.com/journal/2011/1/21/put-some-oop-in-your-app-part-1-creating-a-class.html

I'm using a combination of those two methods.. your actual approach should be whatever workflow you prefer. For me, I like having a separate file for each type of enemy, one for the player, one for background, etc.

There's also a library I've been meaning to look at which is supposed to make inheritance a bit easier:

https://github.com/kikito/middleclass

I think a good starting point for starting to learn modules is this video

http://www.youtube.com/watch?v=WX1Swovbhms

I would also say get to know the features of the editor you are using. You shouldn't have to scroll up and down in a file to find a function that you know the name of. Your editor probably has a feature that lets you type in the name of the function and it will jump right to it.

I think you answered your own question "What do the pros out there do to manage long code?" in your post. Modules.

Also, a tutorial that you may find useful (it's on using external modules, will help tremendously with code organization):
http://blog.anscamobile.com/2011/09/a-better-approach-to-external-modules/

And the follow-up (can help even more in terms of organization):
http://blog.anscamobile.com/2011/09/tutorial-modular-classes-in-corona/

Thanks! I'll look more into modules.

Tom

views:1714 update:2011/10/19 14:58:09
corona forums © 2003-2011