[Tutor] Impossible Else as Exception

Jordan wolfrage8765 at gmail.com
Wed Apr 10 08:18:28 CEST 2013


Thank you all for the feedback and suggestions.  I have never used an 
assertion, before so I will read up on the concept.  But this last email 
about the optimizations makes me want to go with an AssertionError 
exception, since assert is skipped if the compiler is told to optimize.
Alan you are right, the code should be better tested, but test driven 
development seems like it would take me forever to complete even small 
tasks, there is so much to be tested.  I have limited time to program 
with my wife and kids, but do you think test driven development is still 
the way to go?

On 04/10/2013 02:43 AM, eryksun wrote:
> On Tue, Apr 9, 2013 at 8:17 PM, Danny Yoo <dyoo at hashcollision.org> wrote:
>> Going back to the original question: perhaps an assertion here would
>> be sufficient.  Something like:
>>
>>      assert False, "Impossible situation"
> Like "if __debug__" statements, assert statements are skipped by the
> compiler if optimization is enabled. If you want an AssertionError
> here even for optimized code, then explicitly raise
> AssertionError('Impossible situation').
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list