8

I'm reading through .Net Docs and i came across this term "fidelity",

Type safety is also used to help enforce encapsulation by guaranteeing the fidelity of the accessor keywords.

What does it mean (in relation to accessor keywords)?

chakmeshma
  • 246
  • 8
  • 27
  • 1
    Could you provide a link to the page where the term "fidelity" appears ? – Antoine Jul 18 '19 at 15:16
  • https://learn.microsoft.com/en-us/dotnet/standard/tour#type-safety – Patrick Hofman Jul 18 '19 at 15:17
  • From what I can tell, the term "accessor" is incorrect here... it should be "accessibility" or "visibility", referring to the keywords `public` etc. because it's talking about what *other code* can call. I think that contributes to the confusion. Beyond that, it's unclear... perhaps it's referring to the consistency and validity of the state of an object and preventing arbitrary changes to the object by consumers. This is only a "tour" document, though, so don't get hung up on high-level descriptions. – madreflection Jul 18 '19 at 16:38
  • 1
    The number of mistakes in that document is *large*. Holy goodness. I found half a dozen in just a couple of paragraphs. – Eric Lippert Jul 18 '19 at 16:54
  • 1
    @EricLippert - I'm glad you said that. I thought I was going crazy just looking at that slice of it. – madreflection Jul 18 '19 at 16:56

1 Answers1

12

Sigh.

There is simply too much documentation and not enough time for the development team to review it for accuracy in jargon. This overview is a mess of small errors and confusing, non-standard jargon usages.

The paragraph in question is:

Type safety is also used to help enforce encapsulation by guaranteeing the fidelity of the accessor keywords. Accessor keywords are artifacts which control access to members of a given type by other code. These are usually used for various kinds of data within a type that are used to manage its behavior.

Yuck. So much wrong here. "accessor keyword" should be "accessibility level". "Other code" is confusing; "other code" means code which is other than what exactly? Accessibility modifiers control access to members everywhere, not just in "other code". Why are we talking about members and then suddenly switching to data? What does "manage behaviour" mean?

Let's rephrase using standard C# jargon.

Static type checking helps enforce encapsulation by ensuring that a program respects the accessibility levels declared by a member of a type. For example, if type Dog has a private member mother, then static type checking helps ensure that attempts to access that member from code outside the Dog class will be prevented.

Fixing all the rest of the crazy mistakes in this document is left as an exercise to the reader. For example, what's wrong with this code sample?

Dog dog = AnimalShelter.AdoptDog(); // Returns a Dog type.
Pet pet = (Pet)dog; // Dog derives from Pet.
pet.ActCute();
Car car = (Car)dog; // Will throw - no relationship between Car and Dog.
object temp = (object)dog; // Legal - a Dog is an object.
Eric Lippert
  • 647,829
  • 179
  • 1,238
  • 2,067
  • 6
    I entered a github issue with MORE RANTING. https://github.com/dotnet/docs/issues/13466 – Eric Lippert Jul 18 '19 at 17:57
  • 3
    `Car car = (Car)dog;` : Well, if you insist on allowing `Car` to be allowed to inherit from `Dog`: https://i.stack.imgur.com/eoTFN.jpg – Brian Jul 18 '19 at 19:28
  • 1
    @EricLippert - so much is wrong with that code sample. For starters Car car = (Car) dog; won't throw a runtime exception... it just won't compile. – Justin Blakley Jul 19 '19 at 15:45
  • On second though, there could be one way that it does compile, but implementing it would be basically useless and very misleading and dangerous. However, that goes to the point that the documentation is just wrong on many levels. If a developer implemented a static explicit conversion operator. public static explicit operator Car(Dog d) => (Car) null; – Justin Blakley Jul 19 '19 at 18:30
  • But then it would not throw! – Eric Lippert Jul 19 '19 at 20:47
  • It compiles and throws if, say, car is an interface and dog is unsealed. – Eric Lippert Jul 19 '19 at 20:49
  • @EricLippert - True, thanks for clarifying. I was only thinking of ways that the code sample is just bad, incomplete, and misleading. – Justin Blakley Jul 22 '19 at 14:24
  • It's too bad that as of today, the documentation still contains that misleading description ... – Zack ISSOIR Dec 09 '19 at 10:26