Click here to Skip to main content
15,897,519 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Pete O'Hanlon19-May-14 9:11
mvePete O'Hanlon19-May-14 9:11 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Colborne_Greg19-May-14 9:55
Colborne_Greg19-May-14 9:55 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Colborne_Greg19-May-14 8:51
Colborne_Greg19-May-14 8:51 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
PIEBALDconsult18-May-14 18:12
mvePIEBALDconsult18-May-14 18:12 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? PinPopular
_Maxxx_18-May-14 19:02
professional_Maxxx_18-May-14 19:02 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Jörgen Andersson18-May-14 20:30
professionalJörgen Andersson18-May-14 20:30 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
CPallini18-May-14 21:43
mveCPallini18-May-14 21:43 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
kalberts18-May-14 22:33
kalberts18-May-14 22:33 
We have been using the struct practice for years, and I am personally strongly in favor of it. I would like to add a few comments/modifications, though:

First, a set of options is not a function declaration issue, but a system data design issue. Two or more functions referring to, say, page layout properties should not declare "their own" parameter structs (possibly overlooking some essential parameter). The set of options affecting page layout, say, is one well defined set for the entirre application (or even more).

Second, you should never slump together completely unrelated options in one struct, even if one function (or even several) inspects them all. One option struct defines page layout parameters, another one typographical characteristics, a third one the current user. So you might end up with "several" (i.e. a few) option parameters, but not a hundred of them. (For all practical purposes, this second point is also a requirement for my first point.)

Third, as software develops, new options will be added. For an exported library function, it must be prepared to handle calls from applications both newer (supplying a larger struct with added and unknown fields) and older (supplying structs with missing fields) applications, and be able to handle them both. So the struct must identify the version. So one of the fields in the option struct is "This is format 3". An alternative is "This struct contains 44 valid bytes of parameters. The very best is to include both: This struct contains 44 bytes of parameters of format 3" - then you can add parameters in format 3 as long as the extensions are fully compatible, and bump the format code only when an incompatible extension is introduced. So the caller must fill in two extra fields, but then again, the same declaration can be used twenty years later. (Don't expect anyone below thirty to see the value of that...)

Another alternativ is of course the Win32 API way: Start with MyFunction. Then, when one option is added, call it MyFunctionEx. After the second extension, make it MyFunctionEx. After extension eight, it is MyFunctionExExExExExExExEx, and so it continues Smile | :)
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
BobJanova19-May-14 1:13
BobJanova19-May-14 1:13 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Tony Moffatt19-May-14 1:36
Tony Moffatt19-May-14 1:36 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
BobJanova19-May-14 6:58
BobJanova19-May-14 6:58 
JokeRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Kirk 1038982119-May-14 3:51
Kirk 1038982119-May-14 3:51 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
patbob19-May-14 5:57
patbob19-May-14 5:57 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
RafagaX19-May-14 9:35
professionalRafagaX19-May-14 9:35 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
User 483504720-May-14 3:51
User 483504720-May-14 3:51 
GeneralElectronaggedon Pin
#realJSOP18-May-14 4:44
professional#realJSOP18-May-14 4:44 
GeneralRe: Electronaggedon PinPopular
Duncan Edwards Jones18-May-14 5:19
professionalDuncan Edwards Jones18-May-14 5:19 
GeneralRe: Electronaggedon PinPopular
Paul M Watt18-May-14 6:17
mentorPaul M Watt18-May-14 6:17 
GeneralRe: Electronaggedon Pin
Rage18-May-14 22:25
professionalRage18-May-14 22:25 
GeneralRe: Electronaggedon Pin
AlphaDeltaTheta18-May-14 6:53
AlphaDeltaTheta18-May-14 6:53 
GeneralRe: Electronaggedon Pin
#realJSOP18-May-14 7:45
professional#realJSOP18-May-14 7:45 
GeneralRe: Electronaggedon Pin
Duncan Edwards Jones18-May-14 8:11
professionalDuncan Edwards Jones18-May-14 8:11 
GeneralRe: Electronaggedon Pin
#realJSOP18-May-14 10:36
professional#realJSOP18-May-14 10:36 
GeneralRe: Electronaggedon Pin
Gary Wheeler19-May-14 0:50
Gary Wheeler19-May-14 0:50 
GeneralRe: Electronaggedon Pin
#realJSOP19-May-14 5:40
professional#realJSOP19-May-14 5:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Straw Poll

Were you affected by the geomagnetic storms this past weekend?
Communication disruptions, electrified pipes, random unexplained blue-screens in Windows - the list of effects is terrifying.
  Results   119 votes