Defensive programming
The last principle I want to show you is defensive programming. In this paradigm, you try to play it safe by checking as many things and edge cases in code as possible. In a function, for example, you can check at the start of the function whether the parameters are correct. This way, you will prevent a lot of crashes in the long run.
For example, if you have a function that should return the item within an inventory at a certain index, you could write it non-defensively and defensively like this:
func get_inventory_item(index: int): return inventory[index] func get_inventory_item (index: int): if index < 0 or index >= inventory.size(): return return inventory[index]
The second version of the function is defensive because it checks first if the index of the item we want is within the range of the inventory. We do this because if the index is outside...