Jump to content
  • Advertisement
Sign in to follow this  
synth_cat

can function have too many params?

This topic is 4310 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

I'm not sure what "Beginner" means in this place, but I'll just post this question here because it seems to be pretty basic. I just want to know: Are there problems with defining a method that takes a lot of params? Here are some functions from my game that I am somewhat concerned about:
void AddShotQuad(bool light, WORD alpha, WORD red, WORD green, WORD blue,
		         D3DXVECTOR2 pos, float height,
				  float angle, float radius, float tail_length,
				  float tex_u, float tex_v);

AddPuff(bool light, bool face_camera, float grow, float trns,
						WORD red, WORD green, WORD blue,
						float fade, D3DXVECTOR3 pos, 
                                                float u, float v, float size,
						float size_variance,
                                                float speed,               
                                                float pos_offset)


These may seem random or contrived, but, believe me, I actually use them :) and I want to know if they have too many parameters or not. Thanks! -synth_cat

Share this post


Link to post
Share on other sites
Advertisement
Keep It Simple Stupid.

If you ever go over 4 or 5, you're design probably isn't the best. Don't be fooled by Microsoft's APIs. Less is more. Use default parameters with extreme liberty.

Share this post


Link to post
Share on other sites
In C++, a compiler implemention is suggested to support at least 256 parameters for a function.

Share this post


Link to post
Share on other sites
I dont think it is a problem or a bottleneck of any kind.
An extra parameter usually means pushing an extra variable onto the function stack before doing the jump.
The type of the argument is more important. Sending a huge home-made struct by value would be bad for performance if performance is a big concern for your program.

Share this post


Link to post
Share on other sites
Quote:
Original post by synth_cat
I'm not sure what "Beginner" means in this place, but I'll just post this question here because it seems to be pretty basic.


We're pretty liberal with the definition.

Quote:
I just want to know: Are there problems with defining a method that takes a lot of params?


Technical problems, not really. Problems for the programmer who has to remember the order of the parameters and what they are for, and who will get RSI from all the typing, probably.

Quote:
These may seem random or contrived, but, believe me, I actually use them :) and I want to know if they have too many parameters or not.


It looks like some of the parameters could be placed in an array as constants.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
In C++, a compiler implemention is suggested to support at least 256 parameters for a function.


Really? I thought the max was 31 (ie 5 bits).

Share this post


Link to post
Share on other sites
One of the things that you can do to help cut down are your parameters is to group your parameters into classes. One that I see right away in your is your WORD red, WORD blue, WORD green. This could easly become a RBG class. Yes this could be a struct also but by making it a class you could add error checking to make sure the red, blue and green values are valid. You could also add alpha to it just to make it more complete and make it a RBGA class. You can look for other groups like this in your code to clean things up.

theTroll

Share this post


Link to post
Share on other sites
Quote:
Original post by LessBread
Really? I thought the max was 31 (ie 5 bits).

It's implementation defined, but the standard suggests that it be at least 256 (Annex B of the C++ Standard).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!