473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.
Jul 19 '05 #1
2 2834
On 24 Jul 2003 11:55:51 -0700, s_******@yahoo.com (lombrozo) wrote:
It's 1400 lines long. Is the function too big?


Yes.

Jul 19 '05 #2

"lombrozo" <s_******@yahoo.com> wrote in message
news:f1*************************@posting.google.co 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
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
2
by: penny336 | last post by:
dear all, i wrote a class integerSet which contain element as integer here is the driver program main IntegerSet a( n ); a.inputSet(); IntegerSet b (a); IntegerSet c(2*n); c =...
6
by: marcelf3 | last post by:
Hello.. This page opens a window with some information, but everytime the user changes a field in the parent window, the child window needs to be closed. These 2 functions were supposed to do the...
12
by: Susan Cranford | last post by:
Please forgive, I have looked at so much info I can't figure out how to put it together even though I know it must be fairly simple. I have an array of input text boxes (txtDOBn) where n is...
35
by: michael.casey | last post by:
The purpose of this post is to obtain the communities opinion of the usefulness, efficiency, and most importantly the correctness of this small piece of code. I thank everyone in advance for your...
38
by: maadhuu | last post by:
does it make sense to find the size of a function ??? something like sizeof(main) ??? thanking you ranjan.
9
by: shaun | last post by:
Dear all, I realized an error in a previous post, I reproduce it here because I'm still not sure how to solve it: I want to make a templated function which points to one-past-the-end of a...
7
by: bowlderster | last post by:
Hello,all. I want to get the array size in a function, and the array is an argument of the function. I try the following code. /*************************************** */ #include<stdio.h>...
2
by: anon | last post by:
Hello I am working on the optimization of a function, which should do something extensive work. Running the profiler, I identified this function to be the bottleneck. Simplified function...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.