in reply to On scoping temporaries or global settings
in thread One-shot code critique

Doesn't the for-loop construct use more internal resources than a local variable? As comming from the C programming section a waste of resources looks somehow awkwardly to me. But it sure is more readable this way.

Regards,
C-Keen

  • Comment on For - Loop construct 'cheaper' than local variable?

Replies are listed 'Best First'.
Re: For - Loop construct 'cheaper' than local variable?
by Brovnik (Hermit) on Sep 30, 2001 at 02:44 UTC
    You really shouldn't be worryomg about use of reseources at this level.

    Focus on good style, readability, ease of coding, major performance issues, and all that other good stuff.

    A decent compiler should optimise this sort of construct down to almost nothing (at most a single extra test), which will not be noticeable in the overall performance unless it is in the inside of a very tight loop.

    Perl already does some interesting tricks, such as removing if statements from the code and replacing it with and/or, so trying to second guess what the byte code looks like is a waste of time.

    The gain you will get in readability and hence reuse, ability to maintain should outweigh any effect in the code.
    --
    Brovnik