Can global variable be passed into Python function?

Mark H. Harris harrismh777 at gmail.com
Sat Mar 1 00:36:06 CET 2014


On Friday, February 28, 2014 3:03:25 PM UTC-6, Marko Rauhamaa wrote:
> 
> Marko

   ...  and between me and you, here is a snip from dmath.py from the atan(x) function:

    if (n**2 < D(1)):
        a = __atan__(n)
    elif (n == D(1)):
        a = gpi/4
    elif (n == D(-1)):
        a = -(gpi/4)
    elif (n < D(-1)):
        a = __atan__Lt_neg1__(n)
    else:
        a = __atan__Gt_1__(n)

   This if--elif--else  is not only ugly, its just not readable either, and besides that, its not elegant, nor is it humanly helpful...   its does work though, and its absolutely necessary.   ugh.

   First, its not immediately clear what it does. Well, there isn't just one atan(x) routine,  there are at least four of them, depending on whether you're a purist, and they must be selected. 

   Second, because of the strict intent ideology of python in the first place, I can't indent this code to make it more readable without breaking python's syntax. 

   Third, this is a VERY simple if elif block.  More complex ones are much worse... for human reading that is...  

     I know its a pain in the neck, but python does need a switch statement.   Is it a stubborn question?  I don't really think that almost every modern computer language has a switch block because of some C paradigm. I think its because most coders find them useful, at least readable, and therefore essential.

    On the other hand, I have coded many scripts and lots of commercial software that used no switch blocks at all... particularly my C++ and Java stuff. 

    Sooo...



More information about the Python-list mailing list