Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compact assignment syntax #240

Closed
thekid opened this issue Mar 24, 2012 · 1 comment
Closed

Compact assignment syntax #240

thekid opened this issue Mar 24, 2012 · 1 comment

Comments

@thekid
Copy link
Member

thekid commented Mar 24, 2012

Scope of Change

A compact assignment syntax for member initialization in constructors and methods will be added.

Rationale

Less $this.member= $member; typing - especially in value objects.

Functionality

The $this.member notation is used to describe the argument passed to this parameter will end up in the member variable named member.

public class Person {
  protected string $name;

  public __construct($this.name) { }
}

// Equivalent of
public class Person {
  protected string $name;

  public __construct(string $name) { 
    $this.name= $name;
  }
}

This notation may be combined with regular parameters:

public class Person {
  protected static int $nextId= 0;

  protected int $id;
  protected string $name;

  public __construct($this.name, int $id= -1) { 
    $this.id= -1 === $id ? ++self::$nextId : $id;
  }
}

Security considerations

n/a

Speed impact

None, resolved during compile time.

Dependencies

n/a

Related documents

@mrosoiu
Copy link
Member

mrosoiu commented Mar 26, 2012

+1
Less typing = more fun!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants