Re-factoring For a Beginner

Started by
2 comments, last by Tutorial Doctor 9 years, 9 months ago
Phase two in the learning process:

Refactoring!

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:

http://forum.maratis3d.com/viewtopic.php?id=986

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).

Questions:

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?

Notes:

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.

They call me the Tutorial Doctor.

Advertisement
Irrelevant but notice "it should be written in lowercase with an intial capital, that is, "Lua". Please do not write "LUA"... So, please, write "Lua" right!"

LUA - Lovely Universal Airport?

UNREAL ENGINE 4:
Total LOC: ~3M Lines
Total Languages: ~32

--
GREAT QUOTES:
I can do ALL things through Christ - Jesus Christ
--
Logic will get you from A-Z, imagination gets you everywhere - Albert Einstein
--
The problems of the world cannot be solved by skeptics or cynics whose horizons are limited by the obvious realities. - John F. Kennedy

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.

My current game project Platform RPG
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.

They call me the Tutorial Doctor.

This topic is closed to new replies.

Advertisement