Andrew Ducker (andrewducker) wrote,
Andrew Ducker
andrewducker

Thinking about code

  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.
Subscribe

  • Interesting Links for 28-10-2021

    The teaser for "Lightyear" (a new Pixar movie) looks like a lot of fun (tags: pixar space trailer ) Oregon's arboreal smiley (tags: trees…

  • Interesting Links for 27-10-2021

    On dealing with corruption on the Chicago police (tags: police corruption USA Chicago ) European energy crisis proves the lie of 'stable'…

  • Interesting Links for 26-10-2021

    Could Brexit affect beach water quality? (from 2016) (tags: UK waste pollution faeces Europe ) Auto-aiming bow vs. flying targets (a very…

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 38 comments

  • Interesting Links for 28-10-2021

    The teaser for "Lightyear" (a new Pixar movie) looks like a lot of fun (tags: pixar space trailer ) Oregon's arboreal smiley (tags: trees…

  • Interesting Links for 27-10-2021

    On dealing with corruption on the Chicago police (tags: police corruption USA Chicago ) European energy crisis proves the lie of 'stable'…

  • Interesting Links for 26-10-2021

    Could Brexit affect beach water quality? (from 2016) (tags: UK waste pollution faeces Europe ) Auto-aiming bow vs. flying targets (a very…