TL;DR: It might be obvious to you, but not to others.
Why?
More often than not, I used to think that my code is just for me (Narrator: ...
For further actions, you may consider blocking this person and/or reporting abuse
I think sometimes, a change of paradigm can make things more obvious. For example in Clojure
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 beitem.stock > 0
as if the stock = 0 then there is no stock ;)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!
GREAT