Tribler / anydex-core

The Universal Decentralized Exchange
GNU Lesser General Public License v3.0
9 stars 6 forks source link

Both `if` branches have the same code #68

Closed Solomon1732 closed 3 years ago

Solomon1732 commented 3 years ago

In the sub-function there is an if statement in the cmp_items internal function. That if statement checks self.order.is_ask(). However both the if and the else branch have the same code.

https://github.com/Tribler/anydex-core/blob/9d11982332f257e1a94e4aca838e4685bd084707/anydex/core/match_queue.py#L27

Edit: since it seems like it would be a minor issue to solve, I don't mind adding the solution to #67

devos50 commented 3 years ago

Good find, go ahead 👍

Solomon1732 commented 3 years ago

Ah, wait, I think I totally misread the code.

if self.order.is_ask():
    if tup1[1] < tup2[1]:
        return 1
    else:
        return -1
else:
    if tup1[1] < tup2[1]:
        return -1
    else:
        return 1

When looked at in isolation the returned value is -1 if the order is an ask and 1 if not. Basically the results returned are flipped, depending on whether order is an ask or not. Uniting the two cases would break behavior.

My apologies for missing it and opening a frivolous issue. I totally missed the difference when reading it!

devos50 commented 3 years ago

No problem! IIRC, the match queue was made quite close to the conference deadline, so I was a bit in a rush writing it. This did also not result in the most readable code 😁