Implement the cases as functions:

def work_for_case_1():
    return long_computation_1()

def work_for_case_2():
    return long_computation_2()

def _select_case():
    if case1:
      return work_for_case_1
    elif case2:
      return work_for_case_2
    else:
       raise NotImplementedError

def orthogonal_array():
    return _select_case()()

def is_constructible():
    try:
        _select_case()
       return True
    except NotImplementedError:
        return False



On Wednesday, May 14, 2014 2:57:37 PM UTC+1, Nathann Cohen wrote:
>
> > Well then go ahead and add a separate function for every distinct
> > functionality. Then you don't need a hack to distinguish she way caching
> > works.
>
> Volker, we really have a LOT of places in the code which looks like that :
>
> if case_1:
>     if existence:
>         return True
>     else:
>         do_stuff
> if case_2:
>     if existence:
>         return True
>     else:
>         do_stuff
> ...
>
> If we split the boolean/matrix answer, we have two functions :
>
> def f1():
>     if case_1:
>         return True
>     if case_2:
>         return True
>
> def f2():
>     if case_1:
>         do_stuff
>     if case_2:
>         do_stuff
>
> The "if" can be long at times, there are MANY of them, and because one of 
> the two functions would call the other I really don't want any mistake to 
> be made in those "if" --> the two behaviours HAVE to match.
>
> If I split it, we really have to duplicate a lot of tests, and this is not 
> a good design either. I prefer to have one place where the logic is 
> written, there will be less mistakes in the future.
>
> Nathann
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to