Here's a couple of annoying problems I encounter quite often with D's properties. Would having some form of property syntax fix them?

1) Array extensions:

  class Person {

    string name_;

    string name() {
      return name_;
    }

  }

  auto person = getPerson();
  auto firstAndLast = person.name.split(' ');

The above line currently requires parentheses after 'name' to compile.

2) Indexing:

  struct Map(K, V) {

    void opIndexAssign(V value, K key) { ... }
    V opIndex(K key) { ... }

  }

  class WebClient {

    private Map!(string, string) headers_;

    Map!(string, string) headers() {
      return headers_;
    }

  }

  auto client = new WebClient();
  client.headers["User-Agent"] = "MyWebClient";

The compiler says client.headers() is not an lvalue (adding 'ref' in D2 changes nothing).

Reply via email to