Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #7728 > unrolled thread

for-loops in the main function or in the subfunctions?

Started byVictor Porton <porton@narod.ru>
First post2017-04-19 23:48 +0300
Last post2017-04-19 15:04 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.programming


Contents

  for-loops in the main function or in the subfunctions? Victor Porton <porton@narod.ru> - 2017-04-19 23:48 +0300
    Re: for-loops in the main function or in the subfunctions? Julio Di Egidio <julio@diegidio.name> - 2017-04-19 15:04 -0700

#7728 — for-loops in the main function or in the subfunctions?

FromVictor Porton <porton@narod.ru>
Date2017-04-19 23:48 +0300
Subjectfor-loops in the main function or in the subfunctions?
Message-ID<od8ien$1ln1$1@gioia.aioe.org>
I write a function (or rather an OO method) which generates a list of errors 
for a set of transactions (for a moment forget what exactly the word 
"transaction" means, it is irrelevant for my question).

Some errors are per-transaction and some are characterization of the entire 
set of transactions (for example, they may depend on the sum of the paid 
values for all transactions in the set).

Should I make for-loop iterating the transactions in the set in my main 
function or make such loops in the sub-functions which I call (directly or 
indirectly) from the main function?

The first variant (to put the loops into the main function) is a bit shorter 
and a tiny bit faster. However I am unsure about advantages of the second 
variant (to put the loops into the sub-functions rather than in the main 
function).

-- 
Victor Porton - http://portonvictor.org

[toc] | [next] | [standalone]


#7730

FromJulio Di Egidio <julio@diegidio.name>
Date2017-04-19 15:04 -0700
Message-ID<05e70e4c-4aa7-451b-ad56-1f9711ff883b@googlegroups.com>
In reply to#7728
On Wednesday, April 19, 2017 at 10:48:28 PM UTC+2, Victor Porton wrote:
> I write a function (or rather an OO method) which generates a list of errors 
> for a set of transactions (for a moment forget what exactly the word 
> "transaction" means, it is irrelevant for my question).
> 
> Some errors are per-transaction and some are characterization of the entire 
> set of transactions (for example, they may depend on the sum of the paid 
> values for all transactions in the set).
> 
> Should I make for-loop iterating the transactions in the set in my main 
> function or make such loops in the sub-functions which I call (directly or 
> indirectly) from the main function?
> 
> The first variant (to put the loops into the main function) is a bit shorter 
> and a tiny bit faster. However I am unsure about advantages of the second 
> variant (to put the loops into the sub-functions rather than in the main 
> function).

These questions just deserve an it depends unless you at least show some of
the design or code.

Anyway, there is no such thing as a pattern for every single little thing we
do at any level: part you design up front, part is emergent from the
feedback you get when implementing.  Coding in particular should be done
relatively "freely": e.g. my rule of thumb for extracting-abstracting-
reusing code is: not earlier than the *third* time I need the same or almost
the same thing... etc.  In short, let the code tell you what *it* needs.
Also, do not over-engineering: it is akin to premature optimisation, just of
the structures rather than the dynamics.  The optimal code is a balance
between effectiveness and flexibility...

Julio

[toc] | [prev] | [standalone]


Back to top | Article view | comp.programming


csiph-web