Great Intro Tutorial - However what about Clean Code?

Firstly, I’d like to say thank you for the fast paced and easy understandable tutorial with a hands on project. I enjoyed the entire “Speedy Saucer” section. Even though I am a Software Engineer myself, I am new to game development, so I found your guidance quite engaging.

Nevertheless, I would like to mention the significance of “Clean Code” and its principles, such as not repeating yourself (DRY), among others.

:thinking: Why am I bringing this up?

  • what we have experienced when mentoring Junior to Mid-Level Developers at our company, we’ve found that it’s crucial to introduce best practices as early as possible. Given that this course is likely to be taken by individuals completely new to Software Development, it’s important they understand the at least some of the clean code and refactoring methods from the beginning.

  • Your tutorial is great, as I’ve mentioned before. Therefore, at this point of the lectures, it would be a fantastic opportunity to offer an additional 5-10 minutes specifically to the refactoring part where clean code principles are applied. :rocket:

Why is this important?

  • Refactoring code not only improves learning but also support new developers to understand common patterns, such as Factory Pattern, Singleton Pattern, etc.).
  • It enhances
    • code readability,
    • maintainability,
    • overall software quality

:computer: Example for the player script to reduce complexity and code duplication:

# variables can de be declared as const since they are not overwritten
# these can then be placed into a "" File
const FORCE = 1000
# summarizing the moving commands into one object reduces code duplication and complexity
	"move_right": Vector2(FORCE, 0),
	"move_left": Vector2(-FORCE, 0),
	"move_down": Vector2(0, FORCE),
	"move_up": Vector2(0, -FORCE)

# defining an "apply_force" function utilizing the apply_force() Method for code reusability 
func apply_force_in_direction(direction):

# apply the logic for players movement by reducing the amount of if-statements by utilizing the for in loop
func _physics_process(delta):
	for direction in PLAYER_DIRECTIONS.keys():
		if Input.is_action_pressed(direction):

:spiral_notepad: Note this example is an easy & simple approach to implement some clean code principles and refactoring methods

1 Like

I do agree with code standards. But keep in mind that there are several more advanced topics that you added into your clean code which would need their own explanations before being used.

  • const instead of var and why this is good practice
  • dictionary (and probably want to talk about arrays etc)
  • loops

So even if this provides “cleaner” code I find it less readable at the level so far into the course. And in the end I would value understanding the code above following code standards when learning new topics.

But great notes!

1 Like

I have to agree with Naelsh on this one. Yes you are implementing “clean code” principals but like you said the people in this course most likely are just now learning how to write code. We haven’t talked about for loops, const, dictionaries or arrays yet and therefore introducing this code to someone at this level is probably going to scare them off or confuse them. I think the concept of “clean code” is fantastic but it’s kind of hard to write clean code if you don’t know how to write the code at all or just the basics.

Privacy & Terms