Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 128239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:36:14+00:00 2026-05-11T05:36:14+00:00

A colleague of mine refactored this code: private void btnGeneral_Click(object sender, RoutedEventArgs e) {

  • 0

A colleague of mine refactored this code:

private void btnGeneral_Click(object sender, RoutedEventArgs e) {     Button button = (Button)e.OriginalSource;     Type type = this.GetType();     Assembly assembly = type.Assembly;     string userControlFullName = String.Format('{0}.{1}', type.Namespace, button.Name);     UserControl userControl = (UserControl)assembly.CreateInstance(userControlFullName); } 

to this code:

private void btnGeneral_Click(object sender, RoutedEventArgs e) {     Button button = (Button)e.OriginalSource;     Type type = this.GetType();     Assembly assembly = type.Assembly;     UserControl userControl = (UserControl)assembly.CreateInstance(String.Format('{0}.{1}', type.Namespace, button.Name)); } 

saying that you don’t need to create a variable if it is only going to be used once.

My response was that making once-used variables is good practice since it:

  • functions as and reduces comments (it is clear what ‘userControlFullName’ is)
  • makes code easier to read, i.e. more of your code ‘reads like English’
  • avoids super-long statements by replacing parts of them with clear variable names
  • easier to debug since you can mouse over the variable name, and in the cases of e.g. PHP programming without debuggers, it is easier to echo out these variable names to get their values

The arguments against this way ‘more lines of code’, ‘unnecessary variables’ are arguments to make life easier for the compiler but with no significant speed or resource savings.

Can anyone think of any situations in which one should not create once-used variable names?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:36:14+00:00Added an answer on May 11, 2026 at 5:36 am

    I’m with your opinion in this case. Readability is key. I’m sure that the compiler produces the same executable in both cases, with the compilers as intelligent as they are today.

    But I wouldn’t claim ‘always use once-used variables’ either. Example:

    String name = 'John'; person.setName(name); 

    is unnecessary, because

    person.setName('John'); 

    reads equally well – if not even better. But, of course, not all cases are as clear cut. ‘Readability’ is a subjective term, after all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 337k
  • Answers 337k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I stopped using serialization for deep copying anyway, because there… May 14, 2026 at 4:09 am
  • Editorial Team
    Editorial Team added an answer This was a known issue that was fixed in the… May 14, 2026 at 4:09 am
  • Editorial Team
    Editorial Team added an answer You will need to add VerifyValidState to both RuleSets: public… May 14, 2026 at 4:09 am

Related Questions

A colleague of mine states that booleans as method arguments are not acceptable .
A colleague of mine and I have been discussing how to declare variables in
A colleague of mine recently got bitten badly by writing out of bounds to
A colleague of mine is working on a .NET application. He needs to write

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.