|
|
|
|
|
by gjulianm
1449 days ago
|
|
I think that drawing conclusions from these examples is not productive at all. In the wild we're going to see functions such as def make_string_filename(s):
# four lines of regex and replace magic
so that we have code like file_src = make_string_filename(object_name)
file_dst = make_string_filename(object_name_2)
which is much more understandable than eight lines of regex magic where you don't even know what the regex is doing.The problem of not knowing what it does or whether it has side effects or not is more a problem of naming and documentation than DRY. Even then, it's still better than repeating the code all over, simply because when you read and understand the function once, you don't need to go back. On the other hand, if the code is all over, you need to read it again to recognize it's the same piece of code. |
|
additionally, the function should be stateless and have no side effects ;)