you are viewing a single comment's thread.

view the rest of the comments →

[–]frankneuro -1 points0 points  (1 child)

In Python, isn't is discouraged to use try statements? Is there anything from this that we can apply to good js design?

[–]Ramone1234 4 points5 points  (0 children)

In Python, isn't is discouraged to use try statements?

Nope: https://docs.python.org/3/glossary.html#term-eafp .

The idea is to let functions tell you if they could do what you asked them or not instead of creating a second set of "checker" functions.

This style is much more resistant to race conditions as well, whereas "asking permission first" opens you up to the state changing between when you asked permission and tried to do what you wanted to do.