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

The Archive Base Latest Questions

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

I often find I want to write code something like this in C#, but

  • 0

I often find I want to write code something like this in C#, but I am uncomfortable with the identifier names:

public class Car {     private Engine engine;     public Engine Engine     {         get         {             return engine;         }         set         {             engine = value;         }     }     public Car(Engine engine)     {         this.engine = engine;     } } 

Here we have four different things called ‘engine’:

  • Engine the class. Engine seems like a good, natural name.
  • Engine the public property. Seems silly to call it MyEngine or TheCarsEngine.
  • engine the private field backing the property. Some naming schemes will recommend m_engine or _engine, but others say that all prefixes should be avoided.
  • engine the parameter name on the constructor. I’ve seen naming schemes that recommend prefixing an underscore on all parameters, e.g., _engine. I really dislike this, since the parameter is visible to callers via Intellisense.

The particular things I don’t like about the code as written are that:

  • If you change the parameter name in the constructor but miss a use of it in the constructor body, you get a subtle bug that the compiler probably won’t be able to spot.
  • Intellisense has a bad habit of autocompleting the wrong thing for you, and sometimes you won’t notice it’s changed the case. You will again get a subtle bug if the constructor body accidentally ends up this.engine = Engine;

It seems that each name is appropriate in isolation, but together they are bad. Something has to yield, but what? I prefer to change the private field, since it’s not visible to users, so I’ll usually end up with m_engine, which solves some problems, but introduces a prefix and doesn’t stop Intellisense from changing engine to Engine.

How would you rename these four items? Why?

(Note: I realise the property in this example could be an automatic property. I just didn’t want to make the example overcomplicated.)

See also: Am I immoral for using a variable name that differs from its type only by case?

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

    In this case, I would name them exactly as they are in the example.

    This is because the naming is clear as to what data each element holds and/or will be used for.

    The only thing I would change for C#3 is to use an auto-property which would remove the local variable.

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

Sidebar

Ask A Question

Stats

  • Questions 204k
  • Answers 204k
  • 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 According to my experience, Linq to SQL already does some… May 12, 2026 at 8:46 pm
  • Editorial Team
    Editorial Team added an answer From this blog entry. An XA transaction, in the most… May 12, 2026 at 8:46 pm
  • Editorial Team
    Editorial Team added an answer This sounds like a well intentioned idea, but: In my… May 12, 2026 at 8:46 pm

Related Questions

I'm kind of interested in getting some feedback about this technique I picked up
I find this excellent code, posted by aemkei as answers to this questions: How
I want to be better at using NUnit for testing the applications I write,
I'm writing a daemon to monitor creation of new objects, which adds rows to

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.