Is there a name for this anti-pattern/code smell?

前端 未结 13 2455
轻奢々
轻奢々 2021-02-12 16:00

Let me start by saying that I do not advocate this approach, but I saw it recently and I was wondering if there was a name for it I could use to point the guilty party to. So h

13条回答
  •  粉色の甜心
    2021-02-12 16:11

    In defense of the anti-pattern designation, this code lends itself to being used in a few ways:

    1. Object x = MyFunction().payload; (ignoring the return result - very bad)
    2. int code = MyFunction().result; (throwing away the payload - may be okay if that's the intended use.)
    3. FunctionResult x = MyFunction(); //... (a bunch of extra FunctionResult objects and extra code to check them all over the place)

    If you need to use return codes, that's fine. But then use return codes. Don't try to pack an extra payload in with it. That's what ref and out parameters (C#) are for. Nullable types might be an exception, but only because there's extra sugar baked in the language to support it.

    If you still disagree with this assessment, DOWNVOTE this answer (not the whole question). If you do think it's an anti-pattern, then UPVOTE it. We'll use this answer to see what the community thinks.

提交回复
热议问题