Re: Basic question about speed/coding style/memory

Discussion in 'Python' started by Jan Riechers, Jul 21, 2012.

  1. Jan Riechers

    Jan Riechers Guest

    On 21.07.2012 11:02, Andrew Berg wrote:
    > On 7/21/2012 2:33 AM, Jan Riechers wrote:
    >> Block
    >> ...
    >> versus this block:
    >> ...
    >> Now, very briefly, what is the better way to proceed in terms of
    >> execution speed, readability, coding style?

    > Using if/else is the most readable in the general sense. Using return
    > (or break or continue as applicable) in this manner would indicate (at
    > least to me) that it's an exceptional or otherwise special case and that
    > the function can't do what it's supposed to. In that case, I would try
    > to catch an exception rather than use if/else whenever possible. I
    > highly doubt there is a significant performance difference between them.
    >


    Hello Andrew,

    Your answer is right, in other circumstances I also would stick to
    try/except, break-statements in loops and so forth.
    But the question was a bit more elementary.

    Cause, as I understand the interpreter chooses either the "else" (1st
    block) or just proceeds with following code outside the if.

    So if there is some overhead in some fashion in case we don't offer the
    else, assuming the interpreter has to exit the evaluation of the
    "if"-statement clause and return to a "normal parsing code"-state
    outside the if statement itself.

    I hope this explanation makes more sense in what I want to ask ;)

    Jan
     
    Jan Riechers, Jul 21, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. calmar
    Replies:
    11
    Views:
    938
    calmar
    Feb 21, 2006
  2. Jan Riechers
    Replies:
    6
    Views:
    188
    88888 Dihedral
    Jul 23, 2012
  3. Andrew Berg
    Replies:
    0
    Views:
    117
    Andrew Berg
    Jul 21, 2012
  4. Chris Angelico
    Replies:
    2
    Views:
    165
    88888 Dihedral
    Jul 23, 2012
  5. Andrew Berg
    Replies:
    0
    Views:
    122
    Andrew Berg
    Jul 21, 2012
Loading...

Share This Page