Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are public fields and properties interchangeably binary compatible?

In the day job, I work on a VB6 (I know, but don't mock the afflicted...) application that uses a number of libraries we have written (also in the ever illustrious VB6). One of these supporting libraries had a load of private members exposed via public properties, and I was asked to remove the properties, and promote the private member variables into public fields with the same name as the original properties.

Now, I'm no COM expert, but I was under the impression that each and every exposed item on a class gets it's own GUID. Since we would be going from a situation where each value went from 2 Guids (Property Get and Property Let) to one where they only used the one (the public field), I was expecting this to break binary compatibility - but it seems it hasn't done that.

Can anyone explain why?

like image 443
Martin Milan Avatar asked May 26 '10 14:05

Martin Milan


2 Answers

No, it hasn't broken compatibility because it hasn't removed the property get and property let methods. It's just that the compiler is now writing them for you.

Isn't this one of the few areas where VB6 is arguably better than .Net?

  • In .Net public fields behave differently to public properties, and this makes some refactorings difficult and causes confusion.
  • In VB6 public fields behave exactly like public properties, which is why it's possible to switch without affecting binary compatibility. Behind the scenes, the compiler generates property get and set routines for public fields. In a sense VB6 has automatically implemented properties (now advertised as a "new feature" in VB10)...
like image 83
MarkJ Avatar answered Sep 18 '22 13:09

MarkJ


I think it's a bit more subtle than that. You get a GUID for the COM interface (not each individual field/method). As I understand it the binary compatibility attempts to work out if the interface your currently compiling is backwards compatible with a reference version of your DLL (assuming you have one) and only changes the GUID if they are not compatible.

I'm therefore also surprised that it has decided removing all the get/set methods is compatible :/

like image 35
Paolo Avatar answered Sep 20 '22 13:09

Paolo