Function size...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lombrozo

    Function size...

    Hi,

    I'd like to ask all of you experienced, well-structured,
    Object-Oriented programmers out there about function size.

    I am using Visual C++ to create an application, everything is nicely
    structured, plenty of classes and inheritence yadda yadda. That part
    of my code I am happy with. However, I have this one worker thread
    (single function) that I am worried about. It's 1400 lines long.
    Now, I remember while at Uni being told that functions should be about
    one page size maximum (say 60 to 70 lines), but I don't think this is
    applicable for my thread function.

    So, I am worried that this function is too long. But surely,
    different functions must be different sizes because of the context
    they are used, and the purpose they are fulfilling? My function is
    quite simple, it sits in a while loop picking of elements from a
    global array. It then checks the element for various conditions and
    writes any error information to a log file. The elements of this
    array are quite big, and contain quite a bit of data, so it takes
    quite a lot of code to process the element.

    Can anyone give me any advice? Is the function too big? I could
    split it into many smaller functions, but what's the point? It would
    still follow a procedural execution, only now we have the overhead of
    function calls.

    Any help would be much appreciated!

    Thanks,

    Simon.
  • Alf P. Steinbach

    #2
    Re: Function size...

    On 24 Jul 2003 11:55:51 -0700, s_lobo_2@yahoo. com (lombrozo) wrote:
    [color=blue]
    >It's 1400 lines long. Is the function too big?[/color]

    Yes.

    Comment

    • John Harrison

      #3
      Re: Function size...


      "lombrozo" <s_lobo_2@yahoo .com> wrote in message
      news:f1b845e2.0 307240235.f9559 e1@posting.goog le.com...[color=blue]
      > Hi,
      >
      > I'd like to ask all of you experienced, well-structured,
      > Object-Oriented programmers out there about function size.
      >
      > I am using Visual C++ to create an application, everything is nicely
      > structured, plenty of classes and inheritence yadda yadda. That part
      > of my code I am happy with. However, I have this one worker thread
      > (single function) that I am worried about. It's 1400 lines long.
      > Now, I remember while at Uni being told that functions should be about
      > one page size maximum (say 60 to 70 lines), but I don't think this is
      > applicable for my thread function.
      >
      > So, I am worried that this function is too long. But surely,
      > different functions must be different sizes because of the context
      > they are used, and the purpose they are fulfilling? My function is
      > quite simple, it sits in a while loop picking of elements from a
      > global array. It then checks the element for various conditions and
      > writes any error information to a log file. The elements of this
      > array are quite big, and contain quite a bit of data, so it takes
      > quite a lot of code to process the element.
      >
      > Can anyone give me any advice? Is the function too big?[/color]

      Way, way, way too big.

      [color=blue]
      > I could
      > split it into many smaller functions, but what's the point?[/color]

      Your code might become more understandable, easier to maintain, easier to
      reuse, easier to port, better organised, less buggy, easier for a compiler
      to optimise. etc. etc.
      [color=blue]
      > It would
      > still follow a procedural execution, only now we have the overhead of
      > function calls.[/color]

      Is that really an issue, I mean have you timed it both ways and found a
      problem? The overhead of a function call can be measured in nano-seconds (or
      something).
      [color=blue]
      >
      > Any help would be much appreciated!
      >
      > Thanks,
      >
      > Simon.[/color]

      john


      Comment

      Working...