Comment

Comment by smjburton

Some of these newer features don't seem like improvements to the language (e.g. the Walrus operator):

'''

# ===== Don't write this =====

response = get_user_input()

if response:

    print('You pressed:', response)
else:

    print('You pressed nothing')
# ===== Write this instead =====

if response := get_user_input():

    print('You pressed:', response)
else:

    print('You pressed nothing')
'''

The first implementation is immediately clear, even if you're not familiar with Python syntax. If you don't know what the ":=" operator does, the code becomes less readable, and code clarity is traded away in favor of being slightly more concise.

parent smjburton 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton