Click here to Skip to main content
15,888,803 members

Survey Results

"out" parameters: A good idea or a bad idea?

Survey period: 15 Jan 2018 to 22 Jan 2018

Given that it has its own Code Analysis warning we know where some people stand on this.

OptionVotes% 
They are a Good Thing1029.66
They are fine if used wisely43240.91
They are what they are15414.58
They should probably be avoided where possible20119.03
They should never be used. Ever.393.69
I have no idea.12812.12



 
GeneralI prefer to avoid them Pin
den2k8818-Jan-18 2:52
professionalden2k8818-Jan-18 2:52 
GeneralManipulating struct-arrays directly. Pin
Paulo Zemek17-Jan-18 8:19
mvaPaulo Zemek17-Jan-18 8:19 
GeneralLike so many things.... Pin
Dominic Burford17-Jan-18 4:51
professionalDominic Burford17-Jan-18 4:51 
Answernot more than one ref- or out parameter Pin
sx200816-Jan-18 7:17
sx200816-Jan-18 7:17 
Generalno idea or opinion on the matter Pin
Dennis E White16-Jan-18 4:33
professionalDennis E White16-Jan-18 4:33 
GeneralThey are ok if you know what you are doing Pin
RugbyLeague15-Jan-18 21:08
RugbyLeague15-Jan-18 21:08 
GeneralRe: They are ok if you know what you are doing Pin
obermd16-Jan-18 4:39
obermd16-Jan-18 4:39 
GeneralRe: They are ok if you know what you are doing Pin
Foothill16-Jan-18 4:56
professionalFoothill16-Jan-18 4:56 
GeneralThey are what they are Pin
CPallini15-Jan-18 9:33
mveCPallini15-Jan-18 9:33 
GeneralRe: They are what they are Pin
Nemanja Trifunovic18-Jan-18 2:23
Nemanja Trifunovic18-Jan-18 2:23 
GeneralWith tuples, I think they are mostly unnecessary Pin
Marc Clifton15-Jan-18 7:07
mvaMarc Clifton15-Jan-18 7:07 
GeneralRe: With tuples, I think they are mostly unnecessary Pin
OriginalGriff15-Jan-18 11:20
mveOriginalGriff15-Jan-18 11:20 
GeneralRe: With tuples, I think they are mostly unnecessary Pin
Richard Deeming16-Jan-18 3:48
mveRichard Deeming16-Jan-18 3:48 
GeneralRe: With tuples, I think they are mostly unnecessary Pin
Slacker00716-Jan-18 4:21
professionalSlacker00716-Jan-18 4:21 
GeneralRe: With tuples, I think they are mostly unnecessary Pin
Stuart Dootson16-Jan-18 1:12
professionalStuart Dootson16-Jan-18 1:12 
GeneralRe: With tuples, I think they are mostly unnecessary Pin
Mel Padden16-Jan-18 2:43
Mel Padden16-Jan-18 2:43 
GeneralThey are just fine, if used wisely Pin
Slacker00715-Jan-18 3:37
professionalSlacker00715-Jan-18 3:37 
GeneralRe: They are just fine, if used wisely Pin
peterchen15-Jan-18 4:46
peterchen15-Jan-18 4:46 
GeneralRe: They are just fine, if used wisely Pin
Espen Harlinn15-Jan-18 5:01
professionalEspen Harlinn15-Jan-18 5:01 
GeneralRe: They are just fine, if used wisely Pin
Dirk Bahle15-Jan-18 5:24
Dirk Bahle15-Jan-18 5:24 
GeneralRe: They are just fine, if used wisely Pin
peterchen15-Jan-18 5:32
peterchen15-Jan-18 5:32 
GeneralC# TryParse() PinPopular
PeejayAdams15-Jan-18 0:55
PeejayAdams15-Jan-18 0:55 
GeneralRe: C# TryParse() Pin
Slacker00715-Jan-18 3:33
professionalSlacker00715-Jan-18 3:33 
GeneralRe: C# TryParse() Pin
PeejayAdams15-Jan-18 4:33
PeejayAdams15-Jan-18 4:33 
I'd kind of hope that we always want to test the return value!

Whilst I don't see it as the crime of the century, TryParse() does do two things (hence its need for an "out" as well as a return value).

As I suggested, it should, strictly speaking, be split into two methods that do one thing each e.g.
C#
bool IsParseable(string)
T Parse(string)

as opposed to:
bool TryParse(string, out T)

The return value does not relate to the entire purpose of the method and aside from not following SOLID principles, this also has an effect on code readability. For a start we have a method with a verbal name and a boolean value - "bool DoSomething()" is inherently misleading, a bool should answer a question not describe an action.

Also, the fact that we tend to be looking for a negative in the return value means that we tend to wind up with a rather inverted logic.

I would suggest that:
if (int.IsParseable(someString))
    someProperty = int.Parse(someString);
else
    //take action

would be much more readable than:
if (!int.TryParse(someString, out someProperty))
    //take action
98.4% of statistics are made up on the spot.

GeneralRe: C# TryParse() Pin
11917640 Member 15-Jan-18 5:30
11917640 Member 15-Jan-18 5:30 

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.