On Sep 1, 6:51 pm, [EMAIL PROTECTED] (Alex Martelli) > try: > blah blah with as many return statements as you want > finally: > something that gets executed unconditionally at the end
Thanks. I didn't think of that. So design by contract *is* relatively easy to use in Python already. The main issue, I suppose, is one of aesthetics. Do I want to use a lot of explicit function calls for pre and post-conditions and "try/ finally" blocks in my code to get DbC (not to mention a global variable to enable or disable it)? I suppose if I want it badly enough, I will. But I also happen to be a bit obsessive about the appearance of my code, and this does complicate it a bit. The nice thing about having it in the doc string (as per PEP 316) is that, while it is inside the function, it is also separate from the actual code in the function. I like that. As far as I am concerned, the self-test code shouldn't be tangled up with the primary code. By the way, I would like to make a few comments about the "reliability" of Python code. Apparently I offended you the other day by claiming or implying that Python code is inherently unreliable. I think it is probably possible to write very reliable code in Python, particularly for small to medium sized applications, but you probably need top notch software engineers to do it. And analyzing code or *proving* that a program is correct is technically harder without static typing. In highly regulated safety critical domains, you need more than just reliable code; you need to *demonstrate* or *prove* the reliability somehow. I personally use Python for its clean syntax and its productivity with my time, so I am certainly not denigrating it. For the R&D work I do, I think it is very appropriate. But I did raise a few eyebrows when I first started using it. I used C++ several years ago, and I thought about switching to Ada a few years ago, but Ada just seems to be fading away (which I think is very unfortunate, but that's another story altogether). In any case, when you get right down to it, I probably don't know what the hell I'm talking about anyway, so I will bring this rambling to a merciful end. On, one more thing. I see that the line wrapping on Google Groups is finally working for me after many months. Fantastic! I can't help but wonder if my mentioning it to you a few days ago had anything to do with it. -- http://mail.python.org/mailman/listinfo/python-list