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 818733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:11:42+00:00 2026-05-15T02:11:42+00:00

The example below may not be problematic as is, but it should be enough

  • 0

The example below may not be problematic as is, but it should be enough to illustrate a point. Imagine that there is a lot more work than trimming going on.

public string Thingy 
{
    set 
    {
        // I guess we can throw a null reference exception here on null.
        value = value.Trim(); // Well, imagine that there is so much processing to do
        this.thingy = value;  // That this.thingy = value.Trim() would not fit on one line
        ...

So, if the assignment has to take two lines, then I either have to abusereuse the parameter, or create a temporary variable. I am not a big fan of temporary variables. On the other hand, I am not a fan of convoluted code. I did not include an example where a function is involved, but I am sure you can imagine it. One concern I have is if a function accepted a string and the parameter was “abused”, and then someone changed the signature to ref in both places – this ought to mess things up, but … who would knowingly make such a change if it already worked without a ref? Seems like it is their responsibility in this case. If I mess with the value of value, am I doing something non-trivial under the hood? If you think that both approaches are acceptable, then which do you prefer and why?

Thanks.

Edit: Here is what I mean when I say I am not a fan of temp variables. I do not like code like this:

string userName = userBox.Text;
if (userName.Length < 5) {
    MessageBox.Show("The user name " + userName + " that you entered is too short.");
    ....

Again, this may not be the best way to communicate a problem to the user, but it is just an illustration. The variable userName is unnecessary in my strong opinion in this case. I am not always against temporary variables, but when their use is very limited and they do not save that much typing, I strongly prefer not to use them.

  • 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. Editorial Team
    Editorial Team
    2026-05-15T02:11:42+00:00Added an answer on May 15, 2026 at 2:11 am

    First off, it’s not a big deal.

    But I would introduce a temp variable here. It costs nothing and is less prone to errors. Imagine someone has to maintain the code later. Better if value only has 1 meaning and purpose.

    And don’t call it temp, call it cleanedValue or something.

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

Sidebar

Related Questions

The example below throws an InvalidOperationException, Collection was modified; enumeration operation may not execute.
The example below, is just an example, I know that I don't need an
this example below works when hover event is trigered and when its not, its
I have: An XML with some elements. A sub-element that may or may not
EDIT: Changed example below to one that actually demonstrates the SIOF. I am trying
Reproducible example below. I have a simulation loop, within which I occasionally have rows
The example below shows the code I am using to test whether a user
JSFIDDLE EXAMPLE BELOW I want to make the following CSS layout and currently im
The example below is from a REST database driver on Python 2.7. In the
In this example below: my $rs = $schema->resultset('CD')->search( { 'artist.name' => 'Bob Marley' 'liner_notes.notes'

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.