YouTube2Text

A few common code smells to be aware of and how to fix them — Transcript

by The Shaggy Dev · 1,439 words · 202 segments · language en · Watch on YouTube

Full transcript

  1. 0:00a code smell is something in your code
  2. 0:02base that may be indicative of a larger
  3. 0:04problem in the system I use the word may
  4. 0:06here because sometimes there is a
  5. 0:09legitimate reason for code like this to
  6. 0:11exist but just like if you smell smoke
  7. 0:13you should probably make sure the house
  8. 0:14isn't on fire if you come across a code
  9. 0:16smell you should take a moment to
  10. 0:17evaluate it and see if your code needs a
  11. 0:19bit of care and attention so here's a
  12. 0:21few common code smells that you may find
  13. 0:23in your games why they can be concerning
  14. 0:25and how to fix them first up is long
  15. 0:28functions long functions are probably
  16. 0:30one of the most common code smells
  17. 0:31you'll come across we all write them
  18. 0:33from time to time because when you're in
  19. 0:35the zone you're just focused on getting
  20. 0:36the code out and don't want to break
  21. 0:38that flow and that's okay but you should
  22. 0:40come back to some of your longer
  23. 0:41functions later and make sure the
  24. 0:43function is an appropriate length I
  25. 0:45don't like to offer specific length
  26. 0:46recommendations as that just results in
  27. 0:48an arbitrary cutoff point but if you've
  28. 0:50got more than maybe 10 or 20 lines of
  29. 0:52code in a function ask yourself if all
  30. 0:54of the functions code is related to
  31. 0:56doing a single thing or if things could
  32. 0:58be broken out a bit we want to do this
  33. 0:59the soar code is easy to read easy to
  34. 1:02maintain and doesn't contain duplicate
  35. 1:04code for instance a function to
  36. 1:06calculate how much damage to take
  37. 1:07shouldn't also take care of everything
  38. 1:09else related to taking damage such as
  39. 1:11modifying units Health updating the UI
  40. 1:13playing a sound effect emitting some
  41. 1:15particles and so on you may want to
  42. 1:17calculate damage without applying it at
  43. 1:19some point in your game such as for the
  44. 1:20UI but this function could be
  45. 1:22incorporated into another general
  46. 1:23purpose take damage function that
  47. 1:25coordinates all of these tasks together
  48. 1:27when it is time to take damage another
  49. 1:29common issue is having long parameter
  50. 1:31list for functions and there's really
  51. 1:33two main issues with this the first is
  52. 1:35how to make sure code less readable as
  53. 1:37the function declaration probably
  54. 1:38doesn't all fit into a single line on
  55. 1:40your monitor and the other is that it
  56. 1:41implies this function may be too complex
  57. 1:43in one way or another maybe the function
  58. 1:45is trying to do too much or be too
  59. 1:47generic branching internally based on
  60. 1:49what parameters it receives and
  61. 1:51therefore needs a lot of parameters that
  62. 1:53it doesn't need in every invocation or
  63. 1:55maybe the data being passed in really is
  64. 1:57this complicated but it should be
  65. 1:58contained in a data object that some
  66. 2:00sort to make it easier to pass around as
  67. 2:02constantly Gathering 10 separate
  68. 2:04parameters every time you need to call a
  69. 2:05function is going to add a lot of bulk
  70. 2:07to your code and open up the potential
  71. 2:08for data to become out of sync in some
  72. 2:10way next up let's talk about duplicating
  73. 2:13code which is one of the first smells of
  74. 2:15a poorly organized code base
  75. 2:17the first time you copy a few lines
  76. 2:19around here and there and then later
  77. 2:21have to make a change to every single
  78. 2:23occurrence of that code is enough to
  79. 2:25make you realize how important it is to
  80. 2:26keep your code singular and unique if
  81. 2:28the same code is needed throughout a
  82. 2:30single script turn it into a function if
  83. 2:31a lot of different objects need the same
  84. 2:33functionality ask yourself if they're
  85. 2:35similar enough to inherit from a shared
  86. 2:36class or if not another option is to
  87. 2:39create a set of utility functions that
  88. 2:40house commonly need a code such as for
  89. 2:42formatting currency or to create more
  90. 2:44components in your application that can
  91. 2:46be attached to other objects wherever
  92. 2:47they're needed next up is God objects
  93. 2:50and I'm going to explain this one with
  94. 2:51an example so let's say you've got your
  95. 2:53player managing their health internally
  96. 2:54when they heal or take damage and now
  97. 2:57you need to update the UI you skipped my
  98. 2:59video on the Observer pattern so instead
  99. 3:01you just create a global object and use
  100. 3:03it to hold a reference to the player so
  101. 3:04the UI can ping for health changes every
  102. 3:06frame not exactly elegant but it works
  103. 3:09for now so then you decide you want to
  104. 3:10show a score based on how many enemies
  105. 3:12have been killed so you put a few more
  106. 3:14references into this global object then
  107. 3:16you need a few helper functions to
  108. 3:17manage everything and pass some data
  109. 3:19around so you add those in and you might
  110. 3:21as well make it so you can play a few
  111. 3:23sound effects from within this object
  112. 3:24since you're already passing health and
  113. 3:26enemy data around and it's easy to catch
  114. 3:28when something is happening plus you
  115. 3:29haven't really gotten around to figuring
  116. 3:31out how to handle audio yet so really
  117. 3:33where else would it go next thing you
  118. 3:35know you've got a god object on your
  119. 3:37hand an object with no singular purpose
  120. 3:39that essentially acts as a Dumping
  121. 3:41Ground for data and functions you
  122. 3:43couldn't decide where to otherwise place
  123. 3:45this is problematic as global data and
  124. 3:47objects are the singular strands that
  125. 3:49piled up into spaghetti code making it
  126. 3:51difficult to debug and reason about your
  127. 3:53game's State since significant changes
  128. 3:55to the data and function calls can occur
  129. 3:57from anywhere in the app plus once
  130. 3:59you've gone down this path it can make
  131. 4:01it hard to get out of it refactoring
  132. 4:03global data to non-global data generally
  133. 4:05isn't going to be a trivial task and the
  134. 4:07constant temptation of making just one
  135. 4:09more addition to the existing dumpster
  136. 4:11fire is going to be hard to resist there
  137. 4:13is a time and a place for Global objects
  138. 4:15but they should be designed with a
  139. 4:17purpose so ask questions study a few
  140. 4:19design encoding patterns and don't dump
  141. 4:21everything into a singular global object
  142. 4:23and lastly for how much I talk about
  143. 4:26good coding form and the importance of
  144. 4:27design and coding patterns it feels
  145. 4:29important to also take a bit to talk
  146. 4:31about the other side of the spectrum
  147. 4:32don't over engineer things building a
  148. 4:35solution that is much more complex and
  149. 4:37difficult to maintain than what's needed
  150. 4:39is just as bad and sometimes worse than
  151. 4:41having an under engineered solution sure
  152. 4:44that function may be a bit long but that
  153. 4:46doesn't mean you need to make an entire
  154. 4:47class with multiple layers of
  155. 4:48inheritance just to get the link down
  156. 4:50deep dependencies like that are
  157. 4:52difficult to maintain difficult to debug
  158. 4:54and reason about and can often add dead
  159. 4:56code that's not actually needed the goal
  160. 4:58is to make your code flexible enough
  161. 5:00that you can add to it or refactor as
  162. 5:02needed later on but not to take every
  163. 5:04feature as an exercise in designing an
  164. 5:06overly abstract convoluted architecture
  165. 5:08that may never be required I will
  166. 5:10probably discuss this point more in
  167. 5:12depth in a later video but here's a few
  168. 5:14questions I like to ask myself when
  169. 5:16figuring out what I need first off what
  170. 5:18features are required these are the
  171. 5:20things that need to be prioritized in
  172. 5:22the design and can help really inform
  173. 5:24what I'm gonna do next up what features
  174. 5:27are reasonably likely to be needed this
  175. 5:29could be something like an optional game
  176. 5:31mode I want to add if time allows a new
  177. 5:33feature that's still in the prototyping
  178. 5:35stage and so on I'll keep these features
  179. 5:38in mind when coding but their inclusion
  180. 5:40can't override what I know I need and I
  181. 5:42won't take much time or effort to
  182. 5:43support them until I know I need them
  183. 5:45this is the situation to pick the low
  184. 5:47hanging fruit parameterize a function
  185. 5:49create an enumerator to represent
  186. 5:51different configurations
  187. 5:53Etc these are small things that aren't
  188. 5:55going to be a lot of effort to implement
  189. 5:56they're not going to muddy up my code
  190. 5:58but they'll help make it just a little
  191. 6:00bit easier to implement the new features
  192. 6:01that I'm kind of anticipating possibly
  193. 6:03happening and the last question I'm
  194. 6:05going to leave you with is what's the
  195. 6:07scope and impact of the code high impact
  196. 6:10code such as the structure of a level
  197. 6:12should get more attention than code that
  198. 6:13is low in both scope and impact such as
  199. 6:16the callback for a specific function
  200. 6:17section on one menu that will never be
  201. 6:19reused remember Simplicity is often the
  202. 6:22best choice

About this transcript

This page contains the full transcript of A few common code smells to be aware of and how to fix them by The Shaggy Dev, generated from the public captions YouTube serves with the video. The transcript has 1,439 words across 202 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.