Skip to content

Comment on Functional Programming in Pythonparent

Comments

Yeah, I'd much rather read this:

    def can_buy_stuff(user):
        if user is None:
            return False
        balance = user.get_balance()
        if balance is None:
            return False
        balance_credit = balance.credit_amount()
        if balance_credit is None:
            return False
        return balance_credit > 0
Edit: something like Swift's optionals and nil-coalescing syntax might make this easier to read:
   def can_buy_stuff(user):
       return (user?.get_balance()?.credit_amount() ?? 0) > 0
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.