Unsafe Python, safe Clojure

less than 1 minute read

Notes

# dangerous_python.py

def check_validity(emails):
  print("Checking validity")
  emails.pop()
  print("Checked!!")

def send_notification(emails):
  for email in emails:
    print(f"Notified {email}")

emails = [
  "a@a.com",
  "b@b.com",
  "c@c.com",
  "d@d.com",
  "e@e.com",
  "f@f.com"
]

check_validity(emails)
send_notification(emails)
;; safe_clojure.clj

(require '[clojure.string :as str])

(defn check_validity [emails]
  (println "Checking validity") 
  (pop emails)
  (println "Checked!!"))

(defn send_notification [email]
  (str "Sending notification " email))

(def emails ["a@a.com"
             "b@b.com"
             "c@c.com"
             "d@d.com"
             "e@e.com"
             "f@f.com"])

(check_validity [emails])
(println (str/join "\n" (map send_notification emails)))

Updated: