Re: [Vala] default-property-value syntax





On Wed, Mar 5, 2008 at 5:14 PM, Vlad Grecescu <b100dian gmail com> wrote:
On Thu, Mar 6, 2008 at 12:36 AM, Florian Brosch <flo brosch gmail com> wrote:
 > Hi, guys.
 >
 >  A new feature of valac 0.1.8 is a way to set the default-value of
a property:
 >
 >  public int rank {
 >   construct set;
 >   private get;
 >   default ( 5 );
 >  }
 >
 >
 >  We talked about the syntax in #vala. Chipzz and I think that following
 >  looks more appealing:
 >
 >  public int rank {
 >   construct set;
 >   private get;
 >   default = 5;
 >  }
 >

 This triggered my attention too. I haven't seen a language with a
 syntax for this.

 The first thing that crossed my mind was

 public int rank  {
  construct set;
  private get;
 } = 5;
 but that's barely readable when you actually have an implementation
 for getter and setter

 private int _rank = 5;
 public int rank { construct get; private set; };
 would be enough in my opinion.

 On the other hand, since the setter already introduces a keyword,
 'value', one could use:

 public int rank {
  construct set;
  private get;
  value = 5;
 }


 Anyway, if the choice is between the two, I would go for the second
 default = 5

I agree "default" would be a better keyword. But what about the allowable min/max for numeric properties? And parent type for type properties, etc.

public int rank {
  construct set;
  private get;
  default = 5;
  min = 0;
}

Or maybe that's better left to an attribute?
 

 - more readable (as opposed to optimized c++ initialization code that
 obfuscates i=0 into i(0))
_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list



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