Hacker News new | ask | show | jobs
by cellularmitosis 2206 days ago
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