Nested function calls - What's the best practice?
c#, function
Solution
This
var results = GetResults();
SendResults(results);
is better because it's debuggable... Try putting a breakpoin on `SendResults(results)` and watch the value of results.
This is so much important that in the next version of Visual Studio, the 2013 they are adding a way to see return value of functions (see for example here)
This new feature allows you to examine the return value of a function when the developer steps over or out of a function during your debugging session. This is especially useful when the returned value is not stored in a local variable. Consider the following nested function example Foo(Bar()); in this example you can now examine the return value(s) from Bar and Foo, when you step over that line.
From a compiled perspective they are normally the same. The only difference at the IL level is that a slot in the stack has some metainformation with the name of the variable (`results`) or is nameless.
Problem
A small thing, but I will be happy to hear what other people think about it. Which of the 2 code segments below is the best programming practice? ``` var results = GetResults(); SendResults(results); ``` OR: ``` SendResults(GetResults()); ``` I think that the first option is better, but on the other hand option 2 is less code to write (and read). What do you think? I know it's a very basic question, but still...