5 ms·
I understand this is for rapid prototyping and not for production use, as the author clearly stated. But it did remind me of an anti-pattern I see all the time
by fuball63 7y ago
I understand this is for rapid prototyping and not for production use, as the author clearly stated. But it did remind me of an anti-pattern I see all the time at work that does make it's way into production, often for the same reason.
I work primarily in Python, and one thing I see all the time is using dictionaries instead of method arguments. The thought is that when the method evolves over time, you can just add a field to the dictionary. What ends up happening is this dictionary argument is passed up and down the call stack for every nested method call, and sometimes elements are added, edited, or deleted on the way.
Whenever I have to do a refactor of methods like this, it is awful trying to figure out the state of the dictionary, what was originally supposed to be in it, and if it's returned, which parts are actually relevant.
- sooheon 7y agoI'd be interested to hear your thoughts on this perspective: https://youtu.be/YR5WdGrpoug?t=1058 https://youtu.be/YR5WdGrpoug?t=1058
- YawningAngel 7y agoWouldn't it be much more appropriate to use immutable dictionaries in this case (or just not mutate them by convention)? Clojure does this and it seems to work pretty well.
- fuball63 7y agoYes but at that point, designing the structure of the dictionary and not allowing any down-stream method calls to alter it would require the same amount of work/forethought as actually redesigning the method to take X defined inputs and return Y values (and documenting it).
- pdimitar 7y agoInitial effort when refactoring might be the same -- or even bigger -- but it will save you time afterwards. The added peace of mind is not to be underestimated either.
- spidermango 7y agoThis is where good docstrings come in handy. Personally, I think a dict with parameters is better than an endlessly growing method parameters. You can control it a bit further by using tuples instead of dicts for the same idea.
- draw_down 7y agoThe question is why the list of parameters keeps growing endlessly. That’s a smell.
- james-mcelwain 7y agoThis is how it's commonly done in Clojure, and not a problem in my experience. You can define the keys that are relevant: (defn foo [{:keys [bar baz]}] ;; do something... ) (foo {:bar 1 :baz 2}) This isn't as good as a type signature, but makes it easy to know what the dependencies to a function are.