Private Auto

Private Auto



πŸ”ž ALL INFORMATION CLICK HERE πŸ‘ˆπŸ»πŸ‘ˆπŸ»πŸ‘ˆπŸ»

































Private Auto


Sign up with email
Sign up




Sign up with Google



Sign up with GitHub



Sign up with Facebook




Asked
9 years, 8 months ago


Active
1 year, 11 months ago


c# naming-conventions automatic-properties


378k 93 93 gold badges 786 786 silver badges 749 749 bronze badges


260 4 4 silver badges 19 19 bronze badges



from a design point of view, it is better to keep what you have, it helps distinguish what is private, and what is public just by looking at the code.

–  MBen
May 25 '11 at 14:01



possible duplicate of What are the benefits of using properties internally?

–  nawfal
Jun 3 '13 at 17:51


233k 25 25 gold badges 278 278 silver badges 456 456 bronze badges



but later adding logic requires creating a private member to back the property... and you can't actually guarantee other code won't access that member directly

–  Robert Levy
May 25 '11 at 14:13



@Robert: true but at the point of adding the logic you know it will be used properly by existing code. That's all.

–  Henk Holterman
May 25 '11 at 14:17



At least in VS 2015 you also get a reference count to the auto variables.

–  Godspark
Jan 29 '16 at 8:58


238k 51 51 gold badges 345 345 silver badges 399 399 bronze badges


27.8k 6 6 gold badges 58 58 silver badges 93 93 bronze badges



If I could accept more than one answer, I would accept this one too. I think both answers in conjunction provide some good reasoning to avoid this behavior.

–  Biggert
May 26 '11 at 21:12



This is why prefixing private backing members useful. Traditionally, I use the _ , since it will prevent Intellisense from grabbing the private member when writing code, but that's a bad practice in c++. So I'm considering a different prefix, like "p_" for private backing stores that should not be accessed directly. What I'd really like to see is a property-local scope for backing fields, kind of like the way "value" is implicitly declared. Perhaps "thisp".

–  TomXP411
Feb 5 '19 at 19:42





2,199 15 15 silver badges 11 11 bronze badges



makes sense for public properties but not for private - see my answer

–  Robert Levy
May 25 '11 at 14:13



I see slower code execution and larger executables as reason enough not to do something like this. Adding unnecessary property declarations may mean that the program generates extra code to access those member variables. But then, I come from the 8-bit era where every byte counted.

–  TomXP411
Feb 5 '19 at 19:44





8,676 22 22 gold badges 101 101 silver badges 233 233 bronze badges


724 7 7 silver badges 9 9 bronze badges

Senior C++ Developer - Media Streaming for Hollywood
Front-end / Full Stack web developer wanted for leading agriculture SaaS product
Front-end Web Developer for Climate
Climate Central, Inc. No office location
JPMorgan Chase Bank, N.A. Moscow, Russia
PHP Developer (f/m/d) Remote/Homeoffice - WordPress Projects at Enterprise Level

Stack Overflow

Questions
Jobs
Developer Jobs Directory
Salary Calculator
Help
Mobile
Disable Responsiveness


Products

Teams
Talent
Advertising
Enterprise



Company

About
Press
Work Here
Legal
Privacy Policy
Terms of Service
Contact Us



Stack Exchange Network

Technology
Life / Arts
Culture / Recreation
Science
Other


Join Stack Overflow to learn, share knowledge, and build your career.
In a discussion with a peer, it was brought up that we should consider using auto properties for all class level variables... including private ones.
So in addition to a public property like so:
Our private class-level variables would look like this:
I'm on the fence about why someone would want to do this but I can't decide if my reluctance to accept this is because of my own internal brainwashing with how I write my code to the same programming standards and naming conventions I've used for 10 years or because I've never seen this before (for a reason).
I realize it's extra code to type but to be honest, when using auto-properties, I don't think I've ever typed it out due to the 'prop' and 'propg' snippets so it'd be very simple to set up a new snippet to create a private auto property so the extra code doesn't bother me too much since I never have to type it.
Other than aesthetics which may just be my subconscious, are there any issues that could result from using fully private auto properties? Are there any good reasons to do this or not to do it? I've seen a lot of code in my day on stackoverflow, codeplex, codeproject, etc. and I've never seen anyone use this standard.... is there a reason why?
but frankly your classes should not become so big that this is useful.
Your properties won't work as arguments to ref or out parameters.
Private auto-properties are completely pointless, in my opinion. What value does a private auto-property provide that a plain field doesn't?
(It's different when the auto-property is only partially private -- eg, a public/protected getter with a private setter -- or when you use a private non-automatic property to enable you to wrap additional code around the getter/setter.)
It's not nearly as useful for privates as for publics.
Suppose you took your automatic private property and later built some logic into it (being able to do that without breaking anything is the whole point of auto props)...
This would require you to create a private backing member for the property to wrap.
So now you've got two different private ways (member and property) of doing the same thing though one has hidden side effects (the property) and you've now also got the problem of ensuring none of your other methods in the class access that member directly.
Ends up being much more of a headache than just using a private member from the beginning.
What this strategy will do for you is provide an opportunity to put any future changes into the previously autogenerated private property without affecting any of the other code that gets or sets your private property. I personally haven't used this much but it can be beneficial in a case where changes to handling may occur. It also standardizes the code so that fields are always accessed by properties. There are no real drawbacks but it is not really much benefit in most situations either. I think style is really the biggest driver in most situations.
In a discussion with a peer, it was
brought up that we should consider
using auto properties for all class
level variables... including private
ones.
public int MyProperty1 { get; set; }
Moreover it reduces your line of code and Quick Implementation
I'm a firm believer in KISS. I never use a property when a field will do, and I see very little reason to use private accessors (get).
The primary purpose of a property is to be a public accessor for private data. So for simple propreties that do nothing but set or get a value, private accessors and setters make no sense.
Having said that, when you need to transform the data as it's being read, or when you need to perform a side effect when updating the value, you should use a field. Does changing your value raise an event? Then a field is a no-brainer. But then, that's not an auto field that you're declaring with {get; set;}

By clicking β€œPost Your Answer”, you agree to our terms of service , privacy policy and cookie policy

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo Β© 2021 Stack Exchange Inc; user contributions licensed under cc by-sa . revΒ 2021.2.2.38474


Safely Buy And Sell New & Used Cars Privately | PrivateAuto
c# - Using a private auto property instead of a simple... - Stack Overflow
Private Auto X day - YouTube
private auto , private auto Suppliers and Manufacturers at Alibaba.com
Private Auto - Business Service - 2 Photos | Facebook

Outdoor Inn Restaurant
Outdoor Heater
Outdoor Inn Hotel Kata 3
Teenage Pee Hole
Xhamster Kino
h_667" width="550" alt="Private Auto" title="Private Auto">al_c" width="550" alt="Private Auto" title="Private Auto">q_90" width="550" alt="Private Auto" title="Private Auto">usm_0.66_1.00_0.01/e31432360f4e493ba33016f413d775b1.jpg" width="550" alt="Private Auto" title="Private Auto">

Report Page