Duplicated code is always a sign to refactor code. It can be simplified by using a single function with parameters.
Using clear and descriptive names for functions and variables makes the code more readable and understandable.
Long functions should be avoided as they make the code difficult to maintain. Breaking them into smaller functions with a single responsibility improves readability and maintainability.
Refactoring code should be accompanied by writing tests to ensure that the behavior remains the same after making changes.