Re: [Vala] Upcoming changes in object construction syntax



On Sam, 2007-03-03 at 15:37 +0100, Jürg Billeter wrote:
Hi,

just a heads up that we're about to change some parts of the Vala syntax
regarding object construction. The new syntax should be more reasoned
and follow the GObject type system more closely.

It will get a bit harder to follow development of valac in SVN while
we're adapting the new syntax. We'll release a new version when the
breaking changes are done.

/**
 * Example Class to explain the new object construction syntax
 */
public class Maman.Bar {
      /**
       * Properties
       * use construct only if the property needs to be set
       * before the constructor gets executed
       */
      public int x { get; set construct; }

      public int y { get; set construct; }

      public string title { get; set; }

      private int x_y;

      /**
       * Creation Method
       * corresponds to maman_bar_new in C
       * runs first
       * you may only set properties here
       * properties corresponding to parameters declared with
       * construct will automatically be set to the argument
       */
      public Bar (construct int x, construct int y) {
      }

      /**
       * Named Creation Method
       * corresponds to maman_bar_new_with_title in C
       */
      public Bar.with_title (construct string title) {
      }

      /**
       * Constructor
       * runs after the construct properties have been set
       * often not necessary
       */
      construct {
              x_y = x + y;
      }

      static int main (string[] args) {
              /* you may set additional properties by name after the
               * positional arguments */
              var bar = new Bar.with_title ("Hello", x = 10);
              return 0;
      }
}

Migration of existing code:

* Use new creation method syntax
      public construct [with_foo] (...) {...}
              =>
      public Bar[.with_foo] (...) {...}

* Ensure that you don't do anything in the body of creation methods
except setting properties.

* Use new constructor syntax
      Bar () {...}
              =>
      construct {...}

Regards,

Jürg

By now (revision 216) everything mentioned in the upcoming changes has
been implemented except of the variable creation method arguments
(additional properties) feature. We postponed this one since there are
implementation difficoulties.

have fun

Raffaele






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]