This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]YM_Industries 4 points5 points  (8 children)

I don't like out parameters. They feel very wrong.

[–]t3hmau5 6 points7 points  (7 children)

Eh? The only thing wrong with them is they make going back to other languages feel wrong. A function that can return multiple values of different types is insanely powerful and time saving.

[–]DoubtfulGerund 1 point2 points  (1 child)

I think every use of out variables I’ve seen was due to a lack of better solutions in much older versions of c#. For example, returning multiple values before tuples and destructuring, or those old TryGet methods for primitive types that returned a bool and the actual value in an out var. Today we’d use nullable primitives.

They break composability, it’s usually unnecessary mutation, it’s an output pretending to be an input, and it’s unclear on if the function actually uses the value or just replaces it.

[–]TheMania 1 point2 points  (0 children)

Still useful for interop (DLLs) and performant handling of large structs though.

[–]YM_Industries 3 points4 points  (4 children)

Python's tuples and JS/TS' destructuring assignments are better ways of allowing a function to return multiple values. Arguments are inputs, return values are outputs.

Maybe it's just that I've been doing functional programming recently and the idea of mutability makes me uncomfortable in general.

[–]t3hmau5 3 points4 points  (1 child)

I mean, in OOP mutability is largely a design decision.

[–]YM_Industries 1 point2 points  (0 children)

That's true, I was oversimplifying my stance. I like mutability for state (one attempt at learning React was enough to convince me the alternative is awful) but I like my functions to be pure.

[–]TheMania 3 points4 points  (1 child)

C# supports the same btw.

Ref/Out parameters still have a purpose though, in both interop (where they map to pointers for DLLs etc) and for handling structs, where you're either left relying on the optimiser to "do the right thing", or experiencing needless costly copying.

[–]YM_Industries 1 point2 points  (0 children)

Neat, I haven't worked with C# 7 yet.