Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • Can it be split into should_break() and should_continue() methods? (assuming you don't have any genuinely meaningful names you could use like if unauthenticated() break elif not_eligible_for_coupon() continue) Commented Aug 8, 2015 at 16:47
  • Theoretically yes, but that'd push the ugliness to two flow decision methods. Not sure it would help too much, at least with this code. Commented Aug 8, 2015 at 16:51
  • I guess it depends on what you consider ugly. My suggestion was meant to remove the need to return those magic strings. I suppose the other easy answer is that the continue cases can be filter()ed out and the "normal" case can be map()ed, but the break may be tricky depending on how much you care about leaving some but not all items processed at the end. Commented Aug 8, 2015 at 16:57
  • This gives me one idea. I could rewrite it so that the make_flow_decision() was cheap to check once a break was needed. Then, instead of actually breaking out of the loop, I could just continue through it until it's done. It'd mean needless iteration, but if cheap enough that's not so bad. The resulting code could be simplified to, if press_on: process_the_item(). And the check would just emulate a break by continuing until the last item. Commented Aug 8, 2015 at 17:57
  • Instead of strings, why not use enums? Commented Aug 8, 2015 at 18:57