Jump to content

  • Log In with Google      Sign In   
  • Create Account

Re-factoring For a Beginner

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1   Members   


Posted 06 July 2014 - 11:17 AM

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, 06 July 2014 - 03:07 PM.

They call me the Tutorial Doctor.

#2 / Nathan2222_old   Members   


Posted 06 July 2014 - 02:35 PM

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?

Total LOC: ~3M Lines
Total Languages: ~32
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

#3   Members   


Posted 06 July 2014 - 06:21 PM

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

#4   Members   


Posted 06 July 2014 - 11:47 PM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.