fbpx
Welcome, Guest
Username: Password: Remember me
Share your code snippets, screen shots etc. here
  • Page:
  • 1

TOPIC: Interface - "Implements or Inherit", to make a new comparer class

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #890

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Hi Robert, Team, and guys,

I have come across a situation where two different 'approaches' seem to work. Please can you advise me on the best way to do things ?

I wish to make a comparer class for my LINQ query static methods, say to compare one Product with another. It would appear that I can use in X# syntax both 'Implements' and 'Inherit' and each works OK. Here is an image to help explain :-



If I had to guess I would think that both approaches ends up with the same result - but then I don't write compilers ;-0)

Please can you advise me on the best way - if there is a best ! 

Oh! - maybe 'Implements' forces me to have both interface methods !?

HELP !!!

Happy New Year to all,
Phil.
Wales, UK.
Attachments:

Please Log in or Create an account to join the conversation.

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #891

  Frank Maraite's Avatar Frank Maraite Offline Posts: 173
Hi Phil,

I don't know is it intended or not. If I remember the C# syntax right there is no difference, it's the ':' sign.

BTW, both Equals and GetHashCode have to be implemented. This is forced in both ways.

It is important that GetHashCode returns equal values if Equals returns true for both objects. The opposite way this is not important. If Equals returns false GetHashCode may return the same value on both objects, but should return different values of course. Sorry I do not have a like to complete explanation. It has to do with the way hash tables are build.

Frank

Please Log in or Create an account to join the conversation.

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #895

  robert's Avatar robert Offline Posts: 1048
Phil,

Since X# builds on top of the C# Roslyn engine, and since C# uses the Colon ":" both for specifying parent classes and for interfaces there is no real difference between INHERIT and IMPLEMENTS anymore.
They both map to the same C# syntaxnode.

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #897

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Thanks a lot Robert, for clearing that up with a straight forward explanation.

I had a funny feeling that this would be the case after doing the practical tests, and having a good deep think.

For your information I have been a bit silent, BUT, very productive over Christmas and New Year. I have some useful stuff to post in Pearls around the 'Seeding' of suitable test data to a 'Code First' SQL database, using LINQ and some other nice bits, including randomized population etc., including dates and times.

Just got my test 'Stock' app to use Entities to seed 4000 customer orders over a two year period, with more details to follow ..... Only takes a couple of seconds, and the code is nice and clear for any who wish to see it, and follow it through.

This is a big part to 'Code First' I feel, as good test data then allows us to design further code "features and facilities" which we can then test against the more meaningful data. Its very much a feed-back process. Better test data, better features, improved test data, etc., etc., etc..

Will post again in the morning when my mind is fresh ;-0)

I guess you have been away !?
"Happy New Year" to one and all.
Phil.
P.S. my soccer team Sunderland got a point today off Liverpool ;-0) 2 - 2 Draw, yippee !!!

Please Log in or Create an account to join the conversation.

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #898

  Frank Maraite's Avatar Frank Maraite Offline Posts: 173
Robert,

Robert van der Hulst wrote: Phil,

Since X# builds on top of the C# Roslyn engine, and since C# uses the Colon ":" both for specifying parent classes and for interfaces there is no real difference between INHERIT and IMPLEMENTS anymore.
They both map to the same C# syntaxnode.

Robert


then do you plan to change the syntax? Now we can write

IMPLEMENTS Ia, Ib
but only
INHERIT clsX

This is not possible
INHERIT clsX, Ia, Ib

Frank

Please Log in or Create an account to join the conversation.

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #899

  robert's Avatar robert Offline Posts: 1048
Frank,

Frank Maraite wrote: Robert,
then do you plan to change the syntax? Now we can write

IMPLEMENTS Ia, Ib
but only
INHERIT clsX

This is not possible
INHERIT clsX, Ia, Ib

Frank


We could do that. Do you think this is important ?

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #900

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Hey guys,

STOP - its okay the way the syntax is right now!

The reason .NET has Interfaces the way it does is because .NET does not support multiple inheritance. In one sense a crucial over-sight, but deliberate by MS.

We can presently do one 'inherit' and none, one, or more 'implements'. Fine.

The case I discussed is 'unique' in that in effect we can declare a new class with no inheritance, and implement from the interface - which is exactly the same as inheriting from the interface without any 'implements'. For this special case we can do both, and it does make sense.

It sounds confusing, but isn't if you have a mental 'visual' image of the general interface of an object - public members appearing over the surface of a sphere - the sphere is the object. We have a 'patch' of members from the basic class, and then other possible 'patches' of members from defined Interfaces.

I can draw you a nice picture if you like ;-0)

The ways things are then the "Three Pillars of OOPs" is quite concurrent it seems to me. So please don't break it.

Many of our colleagues misunderstand what an 'Interface' is, and possibly confuse the 'general interface' (GI) of an object, with the Public Members which make up a specific Interface.

To me, I feel that MS by using ' : ' for both situations, is not incorrect BUT misses a trick in not making the situation more clear to the coder / designer - as our Inherit and Implements does.

I hope this is clearer to you than it sounds to me typing - in fact the whole situation is quite simple, and Interfaces the way they are get around the fundamental inability to have multiple inheritance. Without which we are frankly 'buggered'.

What we have works ! Don't fix it (please).

Cheers,
Phil.

Please Log in or Create an account to join the conversation.

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #901

  Frank Maraite's Avatar Frank Maraite Offline Posts: 173
Robert,

Robert van der Hulst wrote: Frank,

Frank Maraite wrote: Robert,
then do you plan to change the syntax? Now we can write

IMPLEMENTS Ia, Ib
but only
INHERIT clsX

This is not possible
INHERIT clsX, Ia, Ib

Frank


We could do that. Do you think this is important ?

Robert


never thought about that before. But after reading Phil's answer I would say 'leave it as it is.'. Indeed it is more clear now. How much work is it to disallow inheriting an interface? This makes more sense I think.

We had the discussion about partial classes. I like it now better then before. One prg for each implemention of a specific interface and one for the rest. With inherit and interface keywords it cn be clearly organized.

Frank

Please Log in or Create an account to join the conversation.

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #903

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Hi guys,

I have found a good web short article on OOPs, 3 and 4 Pillars etc. It explains a lot AND probably forms the basis for leaving well alone in X#, or at least till all have had a good think and a full discussion on the matter.

I am not sure how to post a link successfully in the forum so here is my try(s)
themoderndeveloper.com/the-modern-develo...or-four-oop-pillars/

http://themoderndeveloper.com/the-modern-developer/back-to-basics-three-or-four-oop-pillars/

Let me know if neither of these works please.

Cheers,
Phil.

Please Log in or Create an account to join the conversation.

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #904

  Frank Maraite's Avatar Frank Maraite Offline Posts: 173
Hi Phil,

both links work for me.

I like the site, becaue it's a summary of all I learned the last years.

But where is the relation to our syntax discussion?

Frank

Please Log in or Create an account to join the conversation.

Last edit: by Frank Maraite. Reason: Typo

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #905

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Hi Frank,

Before we discuss the syntax of how we would like things, it is the 'meaning' that we must get right.

If we don't get Polymorphism correct then we are doomed. The Implements / Inherit issue was becoming a 'can't type' that issue! Before we define our syntax to exclude 'this or that', we do need to know what MUST be done to get the Polymorphism right.

Having said all that I don't consider myself knowledgeable at all in this field, so I warn others, and then stand aside ;-0)

For my 'feel' on this, I would say we just leave stuff as it is, until we see a problem to fix. Remember that I started this thread with two ways to do the same thing - both worked, and I ask for clarity. So to me this is not a reason to go and change 'stuff', with the possibility of breaking something.

How thinks you 'Batman' ?

Cheers,
Phil.
P.S. next big question, who is Batman ? Robert, Nikos or Chris ??

Please Log in or Create an account to join the conversation.

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #906

  wriedmann's Avatar wriedmann Offline Posts: 1631
Hi Phil,

if I understand Robert correctly, you can write
class MyClass inherit IMyInterface

or
class MyClass implements IMyInterface

and the compiler generates exactly the same code - if IMyInterface is an interface, it used the "interface" meaning, and if IMyInterface would be a class, it would be use the "inherit" meaning.

I like X# explicite declaration of "implements" and "inherit" because it makes code easier to read, without thinking if a thing is a class (from which inherit) or an interface (which implement).

Personally, I would like a compiler error or warning if "implement" is used with a class or "inherit" is used with an interface.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #907

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Hi Wolfgang,

Okay' I go along with what you explain ;-0)

Seems good to me, and in-line with what I was thinking about.

Well done, clean and clear, and good common sense too I feel.

Are you still in the Yucatan ? Did you find the meteor ? Any signs of the odd dinosaur ? 

Hope your journey is a safe one if you still have to return home.

Regards,
Phil.

Please Log in or Create an account to join the conversation.

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #908

  Frank Maraite's Avatar Frank Maraite Offline Posts: 173
Wolfgang, Phil,

Wolfgang Riedmann wrote: I like X# explicite declaration of "implements" and "inherit" because it makes code easier to read, without thinking if a thing is a class (from which inherit) or an interface (which implement).

Personally, I would like a compiler error or warning if "implement" is used with a class or "inherit" is used with an interface.

Wolfgang


that's right.

Indeed it is different:

- with inherting a class we inherit both an interface (all public members) and an, some times partially in case of abstract classes, implementation of this interface.
- otherwise we have to implement this interface completly.

So I would say together with the warning Wolfgang mentioned it would be perfect.

Frank

Please Log in or Create an account to join the conversation.

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #909

  robert's Avatar robert Offline Posts: 1048
Wolfgang,

Wolfgang wrote: Personally, I would like a compiler error or warning if "implement" is used with a class or "inherit" is used with an interface.


I will see what I can do, but this does not have a high priority:
The translation from INHERIT and IMPLEMENTS to the ":" operator is done after the parsing stage when we transform the Antlr parse tree into a Roslyn parse tree. At that moment all we have is type names and no knowledge about whether these are classes or interfaces.
In a later compiler stage (the Binder) the compiler looks up the type names and then we can determine if the types are class or interface.

At that stage we could look back at the original Antlr parse tree and figure out if the type name was part of an INHERIT clause or part of an IMPLEMENTS clause and issue a warning.

We can probably implement this on a rainy Sunday afternoon, but right now we are chasing the last remaining issues in the VO/Vulcan compatibility.

Things like:

- The difference between LONG(p) and LONG(_CAST,p) for different types of p (PTR, BYTE PTR, VOSTRUCT PTR etc)
- The difference between PTR(p), PTR(u), PTR(_CAST,p) and PTR(_CAST,u) where p is a pointer and u a USUAL

I thought I understood this perfectly but Chris just found some cases where things are not what you would expect...

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #910

  Frank Maraite's Avatar Frank Maraite Offline Posts: 173
Robert,

Robert van der Hulst wrote: We can probably implement this on a rainy Sunday afternoon, but right now we are chasing the last remaining issues in the VO/Vulcan compatibility.


I totally agree. It's kind of beauty, not a technical requirement.

Frank

Please Log in or Create an account to join the conversation.

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #911

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
I agree Robert and Frank,

keep this for when you have done the necessary stuff, there is plenty of that I should think ;-0)

At least we have as good as C#, so no need to panic.

You will have to wait a bit longer for your true 'beauty' Frank !

Speak soon,
Phil.
P.S. X# coding going well this morning - will post in Pearls later.

Please Log in or Create an account to join the conversation.

Interface - "Implements or Inherit", to make a new comparer class 2 years 6 months ago #915

  wriedmann's Avatar wriedmann Offline Posts: 1631
Hi Robert,

IMHO this syntax check has a very low priority - there are much more important things to do, even on a rainy day.

Wolfgang

@Phil: yes, I'm in Yucatan, today in Merida after visiting the pyramids in Uxmal yesterday. We have our return flight in the night from Saturday to Sunday
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

  • Page:
  • 1