Is duplicated code bad?
Common ways that code gets duplicated, and techniques for avoiding or refactoring the duplication We all know that duplicated code is generally bad, and “ Don’t Repeat Yourself ” is a well-intended principle that is often mentioned in this regard.
Can duplicated code patterns be eliminated?
The duplicated code pattern was already eliminated in example 0.2.0, so the code is now simply illustrating that code patterns can be eliminated while still maintaining a level of intuitiveness in the code. Now, if we treat this code as a high-level policy containing the business rules in our system, I would take the abstraction level even further.
What's the best way to write good code?
There are a lot of factors. I'll list them roughly in order: Code Reviews. These should be for 100% of code and should frequently include a senior developer. Pair Programming. One of the best (though hard) ways to write good code is do pair programming. The challenge is finding a good pair as not all personalities pair well. Tests.
What if/break code should only be present if k is not none?
The natural thing would be to have the if/break code only be present if K is not None , but this involves writing syntax on the fly a la Lisp macros, which Python can't really do.