Suggestion: properties should be treated as 'virtual members variables'

mike vertex at gmx.at
Tue Sep 5 07:10:59 PDT 2006


Hi!

I hope you don't mind if I throw in some ideas on that.

> 2. Syntax looks like this:
>
> class C
> {
> 	private int m_val;
> 	// Looks just like C# but has the property keyword to distuinguish from  
> a nested function. This is the simplest type of property.
> 	property int Val
> 	{
> 		get { return m_val; }
> 		set { m_val = value; }
> 	}
> }

One could get even further and expand the C#-style syntax:

(1) Get rid of superflous {} characters when there's only one statement.

' property int Val
' {
'      get return m_val;
'      set
'      {
'          assert(value < 20);
'          m_val = value;
'      }
' }

(2) Introduce new "operators". Maybe use operator notation?

' property int Val
' {
'      get return m_val;
'      set
'      {
'          assert(value < 20);
'          m_val = value;
'      }
'      increase
'      {
'          assert(value < 19);
'          return m_val++;
'      }
'      decrease
'      {
'          assert(value > 0);
'          return m_val++;
'      }
' }

(3) Finally - maybe use opXX() notation so there won't be lots of new  
keywords and with the () it fits more nicely into the syntax.

' property int Val
' {
'      opReturn() return m_val;
'      opAssign(int value)
'      {
'          assert(value < 20);
'          m_val = value;
'      }
'      opIncrement()
'      {
'          assert(value < 19);
'          return m_val++;
'      }
'      opDecrement()
'      {
'          assert(value > 0);
'          return m_val++;
'      }
' }

I like (3) very much.

-Mike


-- 
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/



More information about the Digitalmars-d mailing list