Code refactoring in videogames

I’m less than two weeks from releasing Flip, and the main feature remaining to finish and test is in-app purchase. I have no certainty the game will make any money, or if I will touch again any line of code after release. And I am now refactoring the Dialog system. Why?, would a lot of people ask, and it is a very valid question… But to understand why, first some discussion on refactoring.

What is actually to refactor?

By continuously improving the design of code, we make it easier and easier to work with. This is in sharp contrast to what typically happens: little refactoring and a great deal of attention paid to expediently adding new features. If you get into the hygienic habit of refactoring continuously, you’ll find that it is easier to extend and maintain code.

—Joshua Kerievsky, Refactoring to Patterns
[quote taken from wikipedia]

 

Typical examples, usually supported by IDEs, are extracting repeated parts of code from different places, to create a function that can be reused. Or changing the parameters of a function so it can be a little more generic and also reused better. But those are code-level examples of refactoring, and in a general way, refactoring means changing your code to be better. And “better” should be understood as better to “handle the problem it is intended to handle”. So it might happen that the code you wrote at the beginning was just some prototype code and you need to make it more understandable or usable, or that your understanding of the problem at hand has changed, and so the code is no longer good at handling your new conception of the problem.

So of course It makes sense to change bad, rushed code and turn it into something readable, and that should be done as quick as you can, before you forget what that constant meant, or why you do things in a particular order. But after a while, your code stabilizes becomes robust, and it is not so important to touch it again. So how about when your problem changes?

Reinventing the camera, or parts of it

I remember discussions more than 10 years ago with fellow developers about how “Making videogames is like filming a movie but having to develop a new camera for every time”. Nowadays that is not so true, as component based game frameworks (like Unity) allow you not only to reuse the engine, but also parts of functionality, as long as you developed them carefully.

So the “base technology” part of the problem to solve, is not part of what you need to refactor. In a game, the other big part is the game logic itself. And usually, you just develop the game once, on a strict budget and with little time, you release it, maybe you patch it, and never really touch the code again. So… why refactor the dialog system?

Refactoring is also learning

Because, stretching the term a bit, sometimes what you refactor is your understanding of a particular problem. Sometimes you have to redo things to understand on an abstract level what a good solution would be. Because the only thing that you will carry for certain from a project to another, is your understanding on how to solve problems. In my case, the dialog system is a mess. I have several dialogs across the application, each made in a custom way, and I’m having to add a lot of ad-hoc logic to deal with the purchases (showing a dialog, waiting, closing it when another messages comes, etc.). And even though I might never touch this again, I need to learn how to solve this problem with my current tools, so in the next game I will be more efficient. Because if I don’t learn now, anyway I will have to deal with this problem in the future. And doing it the right way from now onward, is much more efficient than doing it wrong forever.

 

392 thoughts on “Code refactoring in videogames

  1. Pingback: cialis from canada
  2. Pingback: Cialis or viagra
  3. Pingback: Sale viagra
  4. Pingback: viagra for men
  5. Pingback: cialis prices 5mg
  6. Pingback: generic ventolin
  7. Pingback: generic for cialis
  8. Pingback: viagra generic
  9. Pingback: viagra for sale
  10. Pingback: viagra 100mg
  11. Pingback: pharmacy online
  12. Pingback: generic cialis
  13. Pingback: levitra dosage
  14. Pingback: order levitra
  15. Pingback: cialis ed
  16. Pingback: canada viagra
  17. Pingback: real casino online
  18. Pingback: order viagra us
  19. Pingback: payday loans
  20. Pingback: payday loans
  21. Pingback: viagra 100mg
  22. Pingback: cialis internet
  23. Pingback: rx generic viagra
  24. Pingback: cialis 20
  25. Pingback: cialis internet
  26. Pingback: 20 cialis
  27. Pingback: viagra pills
  28. Pingback: casino games
  29. Pingback: rivers casino
  30. Pingback: slot games
  31. Pingback: sildenafil 20
  32. Pingback: viagra 100mg
  33. Pingback: viagra pills
  34. Pingback: tadalafil 10 mg
  35. Pingback: viagra dosage
  36. Pingback: viagra generic
  37. Pingback: generic tadalafil
  38. Pingback: buy cialis
  39. Pingback: hydroxychloroquin
  40. Pingback: order Viagra 50 mg
  41. Pingback: Viagra 120mg otc
  42. Pingback: Viagra 50 mg pills
  43. Pingback: viagra cheap
  44. Pingback: Cialis 10mg cheap
  45. Pingback: buy Cialis 40 mg
  46. Pingback: viagra online
  47. Pingback: cheap viagra
  48. Pingback: viagra dosage
  49. Pingback: cheap Cialis 10 mg
  50. Pingback: buy viagra
  51. Pingback: buy cialis
  52. Pingback: viagra
  53. Pingback: genuine viagra
  54. Pingback: cialis capsules
  55. Pingback: cialis pricing
  56. Pingback: cialis on line
  57. Pingback: catapres price
  58. Pingback: ceclor 250mg cost
  59. Pingback: celexa otc
  60. Pingback: sildenafil dosage
  61. Pingback: cipro 500mg pills
  62. Pingback: claritin pills
  63. Pingback: play casino online
  64. Pingback: casino slot games
  65. Pingback: play casino
  66. Pingback: online casinos usa
  67. Pingback: free slots online
  68. Pingback: casino games
  69. Pingback: sr22 insurance
  70. Pingback: rbc car insurance
  71. Pingback: best car insurance
  72. Pingback: cbd oil dogs
  73. Pingback: ed online pharmacy
  74. Pingback: buy liquid viagra
  75. Pingback: cbd oil 300mg
  76. Pingback: viagra gel price
  77. Pingback: viagra po box
  78. Pingback: homework research
  79. Pingback: buy essay cheap
  80. Pingback: viagra 400 mg
  81. Pingback: buying an essay
  82. Pingback: buy cleocin 300mg
  83. Pingback: clonidine purchase
  84. Pingback: clozaril cost
  85. Pingback: cialis at rite aid
  86. Pingback: coreg 25mg usa
  87. Pingback: cialis online
  88. Pingback: compazine canada
  89. Pingback: calgary viagra
  90. Pingback: dissertation paper
  91. Pingback: differin generic
  92. Pingback: diltiazem otc
  93. Pingback: elavil 10mg pills
  94. Pingback: etodolac purchase
  95. Pingback: hyzaar tablets
  96. Pingback: cialis cost
  97. Pingback: viagra vs cialis
  98. Pingback: Read Full Article
  99. Pingback: see this
  100. Pingback: imuran australia
  101. Pingback: lamisil 250 mg usa
  102. Pingback: lopid 300 mg usa
  103. Pingback: lopressor for sale
  104. Pingback: periactin price
  105. Pingback: plaquenil coupon
  106. Pingback: prednisolone pills
  107. Pingback: prevacid canada
  108. Pingback: herb viagra
  109. Pingback: protonix tablet
  110. Pingback: cheapest provigil
  111. Pingback: pyridium cost
  112. Pingback: remeron 30mg nz
  113. Pingback: seroquel price
  114. Pingback: skelaxin pills
  115. Pingback: thorazine cheap
  116. Pingback: cost of toprol
  117. Pingback: tricor australia
  118. Pingback: valtrex canada
  119. Pingback: wellbutrin coupon
  120. Pingback: zanaflex tablets
  121. Pingback: buy zestril 2,5mg
  122. Pingback: why not check here
  123. Pingback: Visit This Link
  124. Pingback: zovirax purchase
  125. Pingback: cost of zyloprim
  126. Pingback: zyprexa usa
  127. Pingback: tadalafil pharmacy
  128. Pingback: aripiprazole cost
  129. Pingback: buy pioglitazone
  130. Pingback: meclizine online
  131. Pingback: leflunomide coupon
  132. Pingback: donepezil usa
  133. Pingback: anastrozole prices
  134. Pingback: buy dutasteride
  135. Pingback: cialis cheap
  136. Pingback: citalopram pills
  137. Pingback: cephalexin usa
  138. Pingback: clindamycin nz
  139. Pingback: permethrin uk
  140. Pingback: 141genericExare
  141. Pingback: erythromycin cheap
  142. Pingback: xytfvgfq
  143. Pingback: estradiol canada
  144. Pingback: ivjgbepo
  145. Pingback: loperamide uk
  146. Pingback: propranolol cost
  147. Pingback: viagra in spain
  148. Pingback: essay paper help
  149. Pingback: lamotrigine nz

Comments are closed.