8 ms·
That's fair. But maybe someone wants to reuse this in another place so they do this: ``` def make_string_filename(s, style="new"): # 2 lines of shared magic
by gcassie 4y ago
That's fair. But maybe someone wants to reuse this in another place so they do this:
```
def make_string_filename(s, style="new"):
# 2 lines of shared magic
if style == "old"
# 2 lines of original magic
elif style == "new":
# different 2 lines of magic
```
When you get here, two totally separate `make_string_filenames()`, each private to the area of code they're relevant to, would be better.
- ParetoOptimal 4y agoThe ideal is having 3 functions I think: - make_string_filename_style1 - make_string_filename_style2 - make_string_filename Then make_string_filename consists of logic to use the right style. Or one function and a Sum type to be called like: makeStringFilename Style1 "somestring" Given sum type: data FilenameStringStyles = Style1 | Style2
- gjulianm 4y agoExcept that there should be only one way to make a filename from a string. Maybe some options like "allow_spaces" if needed but the point of DRY is not only to share code but to share algorithms.