andrewducker: (Default)
[personal profile] andrewducker
  If I have a method:
int DoSomething(string someStuff)
{
  //Do Stuff
  return 42;
}
then effectively I have an unnamed variable that gets set by the return statement, yes?

That being the case, wouldn't it be in some ways clearer to have an explicit, named, variable that gets set instead?

int DoSomething(string someStuff)
{
  //Do Stuff
  returnValue = 42;
}

where "returnValue" is a keyword that's used to return the value.

As it is I frequently end up with code that creates (or sets) a variable at various points through the code just so it can be returned at the end.  Making this an explicit part of the language just makes sense to me.

I assume there are languages out there that do this.

Date: 2010-02-12 11:02 am (UTC)
From: [identity profile] momentsmusicaux.livejournal.com
Ah, so it's an object rather than just a data type? I can see that would be useful.

October 2025

S M T W T F S
    1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 161718
19202122232425
262728293031 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Oct. 17th, 2025 03:44 am
Powered by Dreamwidth Studios