Look before you leap. This coding style explicitly tests for pre-conditions before making calls or lookups. This style contrasts with the EAFPapproach and is characterized by the presence of many if statements.
In a multi-threaded environment, the LBYL approach can risk introducing a race condition between “the looking” and “the leaping”. For example, the code, if key in mapping: return mapping[key] can fail if another thread removes key from mapping after the test, but before the lookup. This issue can be solved with locks or by using the EAFP approach.
These are excerpt from https://docs.python.org/3/glossary.html#term-lbyl
Use EAFP is the best for Python and programming pleasure :D
No comments:
Post a Comment
New comment