Function size...

Discussion in 'C++' started by lombrozo, Jul 24, 2003.

  1. lombrozo

    lombrozo Guest

    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.
    lombrozo, Jul 24, 2003
    #1
    1. Advertising

  2. On 24 Jul 2003 11:55:51 -0700, (lombrozo) wrote:

    >It's 1400 lines long. Is the function too big?


    Yes.
    Alf P. Steinbach, Jul 24, 2003
    #2
    1. Advertising

  3. "lombrozo" <> wrote in message
    news:...
    > 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?


    Way, way, way too big.


    > I could
    > split it into many smaller functions, but what's the point?


    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.

    > It would
    > still follow a procedural execution, only now we have the overhead of
    > function calls.


    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).

    >
    > Any help would be much appreciated!
    >
    > Thanks,
    >
    > Simon.


    john
    John Harrison, Jul 24, 2003
    #3
    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. Madhanmohan S
    Replies:
    5
    Views:
    7,738
    Madhanmohan S
    Sep 3, 2004
  2. Andreas Klemt
    Replies:
    6
    Views:
    11,067
    Peter Theill
    Nov 28, 2004
  3. =?Utf-8?B?QmlkYXJrb3Rh?=

    How to set the DataGrid Row Size to a fixed size.

    =?Utf-8?B?QmlkYXJrb3Rh?=, May 19, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    824
    =?Utf-8?B?QmlkYXJrb3Rh?=
    May 19, 2005
  4. Neil Zanella
    Replies:
    4
    Views:
    484
    Gianni Mariani
    Oct 9, 2003
  5. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,565
    Michael Jung
    May 25, 2008
Loading...

Share This Page