Click here to Skip to main content
11,582,584 members (78,092 online)

Welcome to the Lounge

   

For lazing about and discussing anything in a software developer's life that takes your fancy except programming questions.

Technical discussions are encouraged, but click here to ask your programming question.

The Lounge is rated PG. If you're about to post something you wouldn't want your kid sister to read then don't post it. No flame wars, no abusive conduct, no programming questions and please don't post ads.
 
GeneralRe: CCC 19/5/14 Pin
Rage18-May-14 22:52
professionalRage18-May-14 22:52 
GeneralRe: CCC 19/5/14 Pin
OriginalGriff18-May-14 23:09
protectorOriginalGriff18-May-14 23:09 
GeneralWell played Dorset Cereals... Pin
Keith Barrow18-May-14 21:06
mentorKeith Barrow18-May-14 21:06 
GeneralArgggh! Noooooooo..... Pin
OriginalGriff18-May-14 19:58
protectorOriginalGriff18-May-14 19:58 
GeneralRe: Argggh! Noooooooo..... Pin
Rage18-May-14 22:22
professionalRage18-May-14 22:22 
GeneralRe: Argggh! Noooooooo..... Pin
Kornfeld Eliyahu Peter18-May-14 22:43
professionalKornfeld Eliyahu Peter18-May-14 22:43 
GeneralRe: Argggh! Noooooooo..... Pin
Rob Philpott18-May-14 23:02
professionalRob Philpott18-May-14 23:02 
GeneralRe: Argggh! Noooooooo..... Pin
NeverJustHere18-May-14 23:50
memberNeverJustHere18-May-14 23:50 
GeneralRe: Argggh! Noooooooo..... Pin
Roger Wright19-May-14 8:58
memberRoger Wright19-May-14 8:58 
GeneralSounds about right to me... Pin
V.18-May-14 19:41
professionalV.18-May-14 19:41 
JokeI'm hoping this isn't a (recent) repost Pin
Sander Rossel18-May-14 11:00
professionalSander Rossel18-May-14 11:00 
GeneralRe: I'm hoping this isn't a (recent) repost Pin
MT_18-May-14 21:03
professionalMT_18-May-14 21:03 
JokeRe: I'm hoping this isn't a (recent) repost Pin
Vivic18-May-14 22:14
memberVivic18-May-14 22:14 
GeneralBest Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Marc Clifton18-May-14 10:33
protectorMarc Clifton18-May-14 10:33 
Key-Value Options:

Let's say you have a function that can take a bunch of options for how to build something, say some auto-generated HTML, when passing them as parameters is just too cumbersome? Personally, I would just put all the options into a struct and pass an instance of the struct into the function. The nice thing about that is, the struct (or class, if you wish) documents all the possible options.

Now, in the land of Ruby, I see everybody everywhere using key-value pairs associated with symbols, like this:

{option1: true, option2: "foobar", option3: 42}

Now of course the symbols usually have some intelligent meaning, but you have absolutely no clue what these optional parameters are unless you look up the online documentation (if it exists) and then can be sprawled across numerous pages on the website.

And worse, in the Ruby code, these options are of course usually tested using the symbol:

if opts[:option1] ... end

such that, if you mistype the "key" (symbol), nothing is going to complain to you, unless the programmer checks the option list for unknown options, which I have NEVER seen done.

Now, there's lots of alternatives in the, say, C# world. Your function can take a variable number of parameters. You can require that the caller provides a callback for resolving options. You can just put everything into the function's parameter list, and so forth. Or, like Rubyists, you can pass in a dictionary or some such thing of options.

Valueless Options (aka flags):

So far, the above discussion deals with options that have associated values. There is also the issue of "valueless" options -- if the "key" is present, then the option is "selected." One of the most common ways of passing in valueless options to a function in most languages is of course with an enum, especially when you can use the "or" operator to combine multiple valueless options. Now, mind you, in Ruby, there is no concept of an enum, which is a serious drawback in my opinion.

But I'm curious what people consider to be their own best practice.

Marc
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Pete O'Hanlon18-May-14 10:59
protectorPete O'Hanlon18-May-14 10:59 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Marc Clifton18-May-14 11:08
protectorMarc Clifton18-May-14 11:08 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Eddy Vluggen18-May-14 22:32
professionalEddy Vluggen18-May-14 22:32 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Daniel R. Przybylski19-May-14 6:52
memberDaniel R. Przybylski19-May-14 6:52 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Ed K19-May-14 14:51
memberEd K19-May-14 14:51 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Sander Rossel18-May-14 11:26
professionalSander Rossel18-May-14 11:26 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Pete O'Hanlon18-May-14 11:38
protectorPete O'Hanlon18-May-14 11:38 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Sander Rossel18-May-14 11:48
professionalSander Rossel18-May-14 11:48 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Member 798912218-May-14 22:03
memberMember 798912218-May-14 22:03 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Sander Rossel19-May-14 9:58
professionalSander Rossel19-May-14 9:58 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Andy Brummer18-May-14 11:44
sitebuilderAndy Brummer18-May-14 11:44 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
SoMad18-May-14 12:32
professionalSoMad18-May-14 12:32 
AnswerRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Kornfeld Eliyahu Peter18-May-14 16:57
professionalKornfeld Eliyahu Peter18-May-14 16:57 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Member 798912218-May-14 22:10
memberMember 798912218-May-14 22:10 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Dan Neely19-May-14 2:35
memberDan Neely19-May-14 2:35 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
gggustafson19-May-14 4:09
professionalgggustafson19-May-14 4:09 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Colborne_Greg18-May-14 16:59
memberColborne_Greg18-May-14 16:59 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Pete O'Hanlon18-May-14 20:20
protectorPete O'Hanlon18-May-14 20:20 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Colborne_Greg19-May-14 8:26
memberColborne_Greg19-May-14 8:26 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Pete O'Hanlon19-May-14 8:35
protectorPete O'Hanlon19-May-14 8:35 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Colborne_Greg19-May-14 8:42
memberColborne_Greg19-May-14 8:42 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Pete O'Hanlon19-May-14 8:56
protectorPete O'Hanlon19-May-14 8:56 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Colborne_Greg19-May-14 9:04
memberColborne_Greg19-May-14 9:04 
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
protectorPete 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
memberColborne_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
memberColborne_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
memberPIEBALDconsult18-May-14 18:12 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
_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
mvpCPallini18-May-14 21:43 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Member 798912218-May-14 22:33
memberMember 798912218-May-14 22:33 
GeneralRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
BobJanova19-May-14 1:13
memberBobJanova19-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
memberTony 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
memberBobJanova19-May-14 6:58 
JokeRe: Best Practice Question - How do you prefer to pass a bunch of options to a function? Pin
Member 1038982119-May-14 3:51
memberMember 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
memberpatbob19-May-14 5:57 

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

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


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 7 Jul 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid