Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Function size...

Reply
Thread Tools

Function size...

 
 
lombrozo
Guest
Posts: n/a
 
      07-24-2003
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.
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      07-24-2003
On 24 Jul 2003 11:55:51 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (lombrozo) wrote:

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


Yes.

 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      07-24-2003

"lombrozo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function versus pointer to function, in context of std::function,huh? Alf P. Steinbach C++ 10 07-27-2011 05:51 AM
Function pointer to void function and int function Giannis Papadopoulos C Programming 5 09-05-2005 09:06 PM
How override ALL function calls? (Is there a "function call function"?) seberino@spawar.navy.mil Python 2 08-01-2005 12:38 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Passing a C++ object's member function to a C function expecing a function pointer! James Vanns C++ 7 01-21-2004 02:39 AM



Advertisments