Function parameter limits?
Displaying 1-2 of 2 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Gareth

Hello,

I am very close to finishing my first game in Verge, a Tetris game with additional features (upside down screen, sticky blocks, etc.) but am getting worried about how many parameters I'm passing to my initialisation function.

Is there a limit to the number of named parameters a function can have? Right now I'm up to 12, and I'd rather not have to play with variadic parameters.

Posted on 2010-06-09 08:32:38 (last edited on 2010-06-09 08:33:26)

Overkill

Nah, there shouldn't be any problems with that. But I'd say, for design purposes, try to keep the number of parameters low whenever you can. 12 is probably okay.

As far as I know the limit on parameters to a single function is very very very generous (2^31-1 = 2147483647), and by the time you get there you've already exhausted your memory, and made something completely unmaintainable and incomprehensible anyways. So you really don't need to worry, if you think your code is better with more parameters, go for it. If it was something above 20 args, I'd probably think you're insane (also since functions get slower to call once they get really large, due to stack memory needing to be allocated, you may not want to go TOO large), but that's up to you.

Variadic parameters are more useful for cases when you want a function that can take a variable number of arguments. Most of the time you will not need this, but it can be useful for certain advanced things, like functions you want to have "overloads" for, or functions that do something like find the minimum of all arguments passed. But yeah, I'm guessing it probably isn't necessary here.

So feel free to worry less about VC and more about your Tetris game! It's nice to see someone active around here :D

Posted on 2010-06-09 10:17:44 (last edited on 2010-06-09 10:20:49)


Displaying 1-2 of 2 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.