[Tutor] simple unicode question

Alan Gauld alan.gauld at btinternet.com
Wed Aug 27 21:09:36 CEST 2014


On 27/08/14 15:57, Albert-Jan Roskam wrote:

>> if *fewer* than 1 in 10 operations will raise an exception, then use
>> try...except; but if *more* than 1 in 10 operations will raise an
>> exception, and it is safe to do so, then LBYL may be appropriate.
>
>
> Thanks a lot, Steven! This kind of stuff should be in a book.

It is in lots of books but they aren't Python books; they are generic 
software engineering books. Because this is not really a language 
specific type design issue, its general software design.

 > Do you know of any real life examples where the code is written
 > in such a way that it could switch from AFTP to LBYL

It would be very unlikely since it would almost always be a case of 
premature optimisation. You would need to be inside a very tight loop to 
make that kind of optimisation worthwhile in real world scenarios.
(And the cost of evaluating it would probably outweigh any gains.)

Much more important is to make the code correct and maintainable than to 
worry about slight performance issues before they are a proven issue.
Building those kind of self modifying control flows makes code much more 
error prone and difficult to modify.

The vast majority of performance issues in software are to do with 
blockages in IO processing(network, disk access, human input, etc)
or database processing (big data or complex searches) or in traversing 
complex/deep data structures. Very few real-world performance issues
are related to simple code execution issues.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list