Advertisement Jump to content
Sign in to follow this  
Tutorial Doctor

Re-factoring For a Beginner

This topic is 1655 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Phase two in the learning process:


So, I have done a few quick edits to someone else's code when I knew it wouldn't be that much work. For instance, recently I had to take all of the text in a javascript file and make it internal within a <script> tag in an html file.

Easy Peasy (easier peasier at least)

I've also taken code that had no functions, and put sections into functions with parameters.

That wasn't that bad.

But now:

I need to take code scattered all over a forum, create classes using related code, change the names of all functions and/or variables to more obvious names (if needed), put grouped code into functions with useful parameters (if needed), and package this code into their respective file names (by class). Also, I am trying to make a demo level/game that demonstrates every aspect of the code (how it is used).

I made an attempt here:

How I am making it easier on myself:

I have a document automation app called Editorial that is going to make the re-naming a lot faster (once I have the code organized a bit better). I could also use it for adding functions with parameters to my code faster, and editing existing code (using regular expressions and such).


How can I tackle this in an organized and efficient manner? Step by Step?
How should I package it? As a separate file for each class, or as one file with all classes in it?
The demo game? What could it be like? Style?


I am programming in Lua, so I have more freedom when constructing the way my object orientation works.

One more Thing:
I also have to make several control schemes for the demo game. Edited by Tutorial Doctor

Share this post

Link to post
Share on other sites

A few tips,

  • Take a piece at a time and always be testing it as you go
  • You could write some small tests the verify the code is functioning properly as you go
  • Try to isolate parts of the code that can be re factored a piece at a time.
  • Use a version control system like git, or subversion so you can revert to previous changes if you break something

Unfortunately, I find re factoring to be much harder in a dynamic language like Lua or javascript. If you accidentally leave a piece of code using old interfaces or functions it wont break until that section of code runs. A compiler can find a lot of problems for you before you run. Unfortunately, this isn't an option for you.

Share this post

Link to post
Share on other sites
Very good tips so far HappyCoder. I actually broke something for the project linked above, and couldn't figure out when it happened. I was doing something with a particle system.

I did do small tests and as I went, but I guess I need some way to track the memory usage too (started to get lag at one point, and couldn't diagnose it).

I'm not too deep to change my approach though.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!