Skip to main content

2022-03-30

  • ☀️Daily Log:
    • #til2022 Easier to ask for forgiveness than permission
      • 🌐:
      • 💁‍♂️: There are two coding styles when handling code fails: look before you leap (LBYL) and easier to ask for forgiveness than permission (EAFP). LBYL is when you check for the existence of something before doing something with them. While EAFP is to do something and catch the error if it doesn't exist.
      • 🤔: It is more pythonic to adhere to EAFP because it is more readable to have the path that works to be explicit and the default condition. It also avoids race conditions because you are catching all the exceptions in the except block and you won't be changing in one thread and checking in another.
        • However, it might lead to complicated exception logic and hard to track where the error is
# LBYL
person = {'name': 'John Doe', 'age':30, 'gender': 'male'}
if 'name' in person and 'age' in person and 'gender' in person:
print(f"{person["name"]} is a {person["age"]} year old {person["gender"]}")
else:
print("Some keys are missing.")

# EAFP
person = {'name': 'John Doe', 'age':30, 'gender': 'male'}
try:
print(f"{person["name"]} is a {person["age"]} year old {person["gender"]}")
except KeyError:
print("Some keys are missing")
  • Ring size
    • thumb - 8/18.2mm
    • index - 7/17.3 mm
    • middle - 7.5/17.7 mm
    • ring - 6.5/16.9 mm
    • pinky - 4.5/15.2 mm
  • Retrospective::
    • One week ago:
    • One month ago:
    • One quarter ago:
    • One year ago: