Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Mad4Life

is this function too long?

This topic is 6087 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

now i heard it is bad programming practice to have functions that are way tooo long now i have a function in my game that is exactly 512 lines ( that is like soo much to me) is it too long? should i make it shorter some how? heh that function has more lines then i ever coded before thx

Share this post


Link to post
Share on other sites
Advertisement
Yeah, that''s a bit too long. I can''t remember what the ''optimal'' function length is according to Code Complete, but I know it''s much shorter than 512 lines .

~~~~~~~~~~
Martee

Share this post


Link to post
Share on other sites
lol i havent seen you in a while Martee

yea i thinks its quite long also but with the way the function is set up i can''t think of a way to shorten it without screwing it up

Share this post


Link to post
Share on other sites
Martee:

If functions cannot have more than X amount of lines of code... int main() is a function, your saying that it can only have a certain amount of code?

Just a thought, theres probably some exception rule...

Share this post


Link to post
Share on other sites
maybe i should explain what the role of the function is

its role is to let the user decide how many skill points to put in the 12 skills

i would have to split up the huge switch statement( the function is basically a switch statement)

Share this post


Link to post
Share on other sites
Could you make a class rather than a function, one class for each skill, or a class called monster and have it have each skill as a variable?

Making it as a class or struct would be a good idea.

Then you can call

cout<<"What is your HP?";
cin>> myMonster.hitPoints;

In a function called checkStats()

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!