On 10 September 2010 13:14, Roelof Wobben <rwob...@hotmail.com> wrote:
> Hello , > > So my book teach me the wrong principle. > But can everything programmed on Eafp. > > If you dont know if something is a list, a tuple or a string, you can get a > lot of nested try except think. > > Roelof > Hi Roelof, I don't think EAFP is wrong, and neither is LBYL, it all depends on the circumstances. Python makes it easy to use EAFP, especially compared to languages like Java or C++. While EAFP is great, it's not always the best way to proceed. Sometimes you want programs to be very robust and secure, this is where LBYL comes in - it is quite often used in online transaction processing and other areas where absolute certainty is more important than any other consideration. EAFP tends to use less code and is faster to use, while LBYL principles makes your program more bulletproof. For now, I suggest you stick to the EAFP principles, it's not wrong and it's one of the reasons I like Python so much - it allows you to focus on solving a particular problem and does not expect you to jump through a number of hoops to just get something simple done. And, before you ask, you can indeed follow LBYL principles in Python if you want to, but you only have to do it if you really want to, not because the compiler forces you to. Consider these principles to be tools in your toolkit, sometimes you need a hammer, other times a saw, each tool (principle) is suited to a particular situation. Go ahead and try both, you will find one works better in a given scenario than the other. Regards Ewald
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor