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

  • Home
  • SEARCH
  • 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

Related Questions

A colleague of mine asked me to write a homework for him. Although this
A colleague of mine is using a horrible source code editor that leaves strange
Hello I have a colleague of mine who is a procedural code developer and
A colleague of mine wants to use my python 2 code on his OS
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
the other day a colleague of mine stated that using static classes can cause
My colleague insists on explicitly specifying the namespace in code as opposed to using
A colleague of mine is working on a .NET application. He needs to write

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.