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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:06:40+00:00 2026-05-11T16:06:40+00:00

I have inherited some code that uses the ref keyword extensively and unnecessarily. The

  • 0

I have inherited some code that uses the ref keyword extensively and unnecessarily. The original developer apparently feared objects would be cloned like primitive types if ref was not used, and did not bother to research the issue before writing 50k+ lines of code.

This, combined with other bad coding practices, has created some situations that are absurdly dangerous on the surface. For example:


Customer person = NextInLine(); 
//person is Alice
person.DataBackend.ChangeAddress(ref person, newAddress);
//person could now be Bob, Eve, or null

Could you imagine walking into a store to change your address, and walking out as an entirely different person?


Scary, but in practice the use of ref in this application seems harmlessly superfluous. I am having trouble justifying the extensive amount of time it would take to clean it up. To help sell the idea, I pose the following question:

How else can unnecessary use of ref be destructive?

I am especially concerned with maintenance. Plausible answers with examples are preferred.

You are also welcome to argue clean-up is not necessary.

  • 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-11T16:06:41+00:00Added an answer on May 11, 2026 at 4:06 pm

    I would say the biggest danger is if the parameter were set to null inside the function for some reason:

    public void MakeNull(ref Customer person)
    {
        // random code
        person = null;
        return;
    }
    

    Now, you’re not just a different person, you’ve been erased from existence altogether!

    As long as whoever is developing this application understands that:

    By default, object references are passed by value.

    and:

    With the ref keyword, object references are passed by reference.

    If the code works as expected now and your developers understand the difference, it’s probably not worth the effort it’s going to take remove them all.

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

Sidebar

Related Questions

I have inherited some legacy PHP code what was written back when it was
I have some C# / asp.net code I inherited which has a textbox which
I have inherited a very old database that needs some data to be updated.
I have inherited a visual studio 2003 project which uses some custom build steps.
I have inherited a project that has class libraries written in VB.NET, some of
I have a some JPA entities that inherit from one another and uses discriminator
I have inherited a middle tier system with some multi-Threading issues. Two different threads,
I'm looking for some way to effectively hide inherited members. I have a library
I have inherited a client site which crashes every 3 or 4 days. It
I have inherited an old crusty PHP application , and I'd like to refactor

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.