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 [import]uid: 55068 topic_id: 16285 reply_id: 316285[/import]

Aha - I have just discovered…

Text Folding!

Lets you expand / hide areas of your code.

BBEdit and TextMate both do this.

Tom [import]uid: 55068 topic_id: 16285 reply_id: 60615[/import]

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

[import]uid: 19626 topic_id: 16285 reply_id: 60630[/import]

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! [import]uid: 41884 topic_id: 16285 reply_id: 60632[/import]

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 [import]uid: 49447 topic_id: 16285 reply_id: 60656[/import]

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

http://www.youtube.com/watch?v=WX1Swovbhms [import]uid: 38820 topic_id: 16285 reply_id: 60686[/import]

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. [import]uid: 67839 topic_id: 16285 reply_id: 60691[/import]

I think you answered your own question “What do the pros out there do to manage long code?” in your post. Modules. [import]uid: 5833 topic_id: 16285 reply_id: 60703[/import]

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/ [import]uid: 52430 topic_id: 16285 reply_id: 60732[/import]

Thanks! I’ll look more into modules.

Tom [import]uid: 55068 topic_id: 16285 reply_id: 61280[/import]