I think sometimes, a change of paradigm can make things more obvious. For example in Clojure
(def ids [1 2 3 4 5])
(defn retrieve [id]
(when (contains? ids id)
It is quite readable as the vocabulary of functions are more relevant.
Haven't tried Clojure but boy that is a whole new level of readability. Thanks for the tips. I agree, this article is merely baby steps to something bigger like switching to Clojure.
Good tips. I think reading the logic out as a sentence is definitely a great way to realise if it will make sense to others at first glance. If it doesn't read as a proper sentence, then it likely isn't going to easily make sense to others.
Btw, small thing, but item.stock >= 0 should be item.stock > 0 as if the stock = 0 then there is no stock ;)
item.stock >= 0
item.stock > 0
Hey, that is true! My mistake. Thanks for correcting me. I've amended the article.
I didn’t know how much more efficient .some and .every were compared to filter. I definitely need to refactor my code that fit this exact use-case. Thank you for sharing!
Be careful when making these logic changes. Check that your unittesting will catch incorrect logic since there are several potential logic changes, should && become ¦¦...
Ah yup, that is true. Refactoring should always be done with tests beforehand. I missed that out. Thanks for the tips!
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.