- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1
 
Closed
Description
Scope of Change
A compact syntax for simple methods will be introduced
Rationale
Slightly less return $this.member; typing - especially in value objects.
Functionality
The -> expression; notation is used as a shorthand for { return expression; }.
public class Person {
  protected string $name;
  public string getName() -> $this.name;
}
// Equivalent of
public class Person {
  protected string $name;
  public string getName() {
    return $this.name;
  }
}Combined with the compact assignment syntax described in RFC #240 and the fluent interface shorthand in RFC #252 we can now write value object as follows:
public class Person {
  protected string $name;
  public __construct($this.name= null) { }
  public void setName($this.name) { }
  public this withName($this.name) { }
  public string getName() -> $this.name;
}Security considerations
n/a
Speed impact
None, resolved during compile time.
Dependencies
n/a
Related documents
- Dart's "
=> e;shorthand" - RFC Compact assignment syntax #240 - Compact assignment syntax
 - XP Language's anonymous functions use this (slightly different, e.g. in 
return #{ $a -> $a + 1 }.(2); // 3it separates the arguments from the body, but this still has chances for recognition).