views:

168

answers:

3

Continuing with the series "Hidden features" I think it's time to Delphi Prism. I believe that's a great way to encourage the development of delphi prism, is that we all share what we discovered in the daily use of this great language.

alt text

Bye.

+4  A: 

Most definitely interface delegation, it's the part I miss the most in C#.

I tried to explain it a bit more detailed in this prismwiki article

Or that one can constrain generic type parameters to be Enums or Delegates. (Which C# simply won't allow)

There's more to it, obviously. But the other useful features it has over C# are already all over the marketing stuff from RO and CG. So not really hidden. ;-)

Robert Giesecke
+1 This feature is really amazing. There's one thing though. I created two interfaces with the same method and implemented then in a class via delegation to find out what would happen in case of collisions. The compiler silently used the definition from the first field. I see this as a problem. What do you think?
Jordão
You can, and should IMO, tell the compiler which member implements which one of which interface. IOW: method Abc; implements IInterface1.SomeMethod;method Def; implements IInterface2.SomeMethod; You can ask a new question on Stackoverflow if you want more detailed infos. Comments don't scale well. ;-)
Robert Giesecke
+2  A: 

First of all: Class contracts. It's on the Oxygene language since it was still called Chrome and will find it's way into C# only with the upcoming release of .NET 4.0.

Then it's the parallel support & future variables. Just by using declarations you can order to execute certain methods in background threads.

Last, but not least, I love the AOP feature 'Cirrus'. Actually it's used for AOP, but I see it more as an interface to write plugins for the compiler that will be executed on defined locations in your code.

Sebastian P.R. Gingter
+2  A: 

Auto-notifying properties.

This:

type Foo = public class
  public property Name : String; notify;
end;

Is equivalent to this in C#:

public class Foo : INotifyPropertyChanged, INotifyPropertyChanging {
  private string _name;

  public event PropertyChangingEventHandler PropertyChanging;
  public event PropertyChangedEventHandler PropertyChanged;

  protected OnPropertyChanging(PropertyChangingEventArgs e) {
    if (PropertyChanging != null) {
      PropertyChanging(this, e);
    }
  }

  protected OnPropertyChanged(PropertyChangedEventArgs e) {
    if (PropertyChanged != null) {
      PropertyChanged(this, e);
    }
  }

  public string Name {
    get { return _name; }
    set {
      if (value != _name) {
        OnPropertyChanging(new PropertyChangingEventArgs("Name"));
        _name = value;
        OnPropertyChanged(new PropertyChangedEventArgs("Name"));
      }
    }
  }
}
Jordão
+1, this is awesome!
Jeroen Pluimers