Questions tagged [out-parameters]

6 questions
32
votes
9 answers

Is there a better way to use C# dictionaries than TryGetValue?

I find myself often looking up questions online, and many solutions include dictionaries. However, whenever I try to implement them, I get this horrible reek in my code. For example every time I want to use a value: int x; if…
Adam B
  • 1,506
  • 2
  • 12
  • 20
15
votes
3 answers

non-optional pointers vs. non-const references in C++

In Other C++ Features, Reference Arguments of the Google C++ Style Guide, I read that non-const references must not be used. All parameters passed by reference must be labeled const. It is clear that looking at function calls that use references…
Wolf
  • 630
  • 1
  • 6
  • 24
8
votes
4 answers

Function that modifies an argument, should I return the modified object?

We have a function that modifies a JS object, by adding some custom properties to it. The function doesn't return antyhing addTransaction: function (obj) { obj.transactionId = this.getTransactionId; obj.id = this.recordId; }, Somebody…
Ruan Mendes
  • 806
  • 2
  • 8
  • 12
6
votes
4 answers

Is using "out" or "ref" parameters in Java methods to return extra values bad?

I happened to create a mutable class like this: class Mutable { private T value; public Mutable() { this.value = null; } public Mutable(T value) { this.value = value; } T get() { return this.value; } void set(T value) {…
hyde
  • 3,744
  • 4
  • 25
  • 35
3
votes
2 answers

Should a method modifying object passed as a parameter return the modified object?

I have some incoming request - it's an instance of class generated from api specification - POJO with public getters/setters. I would like to normalize some values. For example dimensions (to use metric system). I have a service class which has…
Shaolin
  • 33
  • 5
0
votes
5 answers

Named output parameters vs return values

Which code is better: // C++ void handle_message(...some input parameters..., bool& wasHandled) void set_some_value(int newValue, int* oldValue = nullptr) // C# void handle_message(...some input parameters..., out bool wasHandled) void…
Abyx
  • 1,439
  • 4
  • 14
  • 20