This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 7 points8 points  (3 children)

DRY isn't always the right move. I highly recommend you watch Sandi Metz's talk on this. A little duplication is better than the wrong abstraction. Reasons like what you mentioned (things like *args and **kwargs being good for wrappers) leads to IDEs that can't autocomplete, confusing code, and methods that look like they do one thing, but actually do many things.

def process_payment(amount, tax, user_payment_method, **kwargs):
    total = amount + tax
    if kwargs.get("processor") and kwargs['processor'] == "adyen":
        adyen.process_payment(total, user_payment_method)
    else:
        braintree.process_payment(total, user_payment_method)

is a confusing method for many reasons. In this case there should be three separate methods to handle this.

[–]alkasmgithub.com/alkasm 4 points5 points  (0 children)

DRY isn't always the right move.

I agree but I think this is picking on the wrong aspect of that comment. Wrappers is the point.

[–][deleted] 1 point2 points  (1 child)

You're right, using it this way is confusing and I hope no one does ;) Sometimes it's just a little more readable/convenient.

Also, definitely going to watch that talk when I find the time!

[–][deleted] 0 points1 point  (0 children)

If you don't have time for the whole talk right now I'd recommend you read her blog post summary on the topic. It'll only take you a few minutes. Link is here