p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning Python: Using Python 2.6 and Python 3.1 (http://p2p.wrox.com/forumdisplay.php?f=545)
-   -   Using Exceptions for Flow Control? (http://p2p.wrox.com/showthread.php?t=89671)

DrGaribaldi March 24th, 2013 01:09 PM

Using Exceptions for Flow Control?
From a software engineering perspective, using exceptions for flow control is considered a bad practice; exceptions should be used for ... exceptions (exceptional/unexpected behavior, failed preconditions), yet many examples in this book do it. Is this something that Python programmers do often or is the author doing this to illustrate the existence of exceptions? It seems like if the intent is to teach people about a topic, it should be taught in a way that mirrors how it ought to be used (and NOT how it ought NOT be used).

For example, one could argue that there exists a precondition for accessing an element of a dictionary that has_key(key) method should return True. Why not then call that method instead of blindly using the key and catching the exception?

All times are GMT -4. The time now is 09:20 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.