Addition of the keywords 'get
', 'get[]
', 'set
' and 'set[]
' to provide special syntactic support for accessor methods.
Jeff Walker (language designer)
Experts to Contact: Status: Accepted into v0.6 (Prior to 2007-03-15)Language clarity and so methods can appear as properties.
Reason:Get and set methods are so common yet their use can be hard to read.
Description:Any one of these keywords could be placed before a method name (as a name modifier). It would be considered part of the name and could be overloaded based on the differences. Sets would be invoked by assigning to the base name. Gets would be invoked when using the base name on the right hand side of an expression. get[] and set[] would be used in the same situation but allow an extra index argument. With set[] the index would be the first argument followed by the value to set to. Get and set methods would have standard forms enforced by the language.
One issue is what to name properties. Normally a property may be named property then the accessors are name getProperty and setProperty respectively. However with the use of these keywords ambiguities would occur if the properties and methods were named the same.
Example:
module
{
public class Entry
{
personal entryName :string;
public get name() -> string
{
return entryName;
}
}
entry :Entry = create Entry();
out <- entry.name; //Uses the get method
}