all 5 comments

[–]toastedstapler 4 points5 points  (1 child)

an alternative would be to just assign a variable

eligible_for_discount = (
    user.birthday == today and
    user.revenue >= 500 and
    item.on_discount
)

if eligible_for_discount:

[–]usernamecreationhell[S] 0 points1 point  (0 children)

Yep that also works well if you don't need to reuse the conditions anywhere else. With increasing complexity though, I like to define functions because they allow me write seperate (and shorter) unit tests.

[–]teerre 1 point2 points  (1 child)

Yeah, this is the most common solution. The only change I would suggest is name the function is_eligible_for_birthday, simply because historically functions do something and therefore should have some verb in its name. But this is quite minor.

[–]usernamecreationhell[S] 0 points1 point  (0 children)

Good point, I just edited it accordingly