N9I - 2/4/2010

Written on Fri, 05 Feb 2010 07:06:50 +0000 - Last updated on Tue, 09 Feb 2010 08:01:50 +0000A journal entry in the development of the N9I programming language, dated February 4, 2010.

Annotations for Object Properties

N9I supports the following annotations that can be placed above object methods: #@get Foo public Object getFoo() ... #@set Foo public void setFoo(Object foo) ...The @get and @set annotations indicate which methods N9I should use when client code tries to read from or write to a property: someObject.Foo = myFoo; // calls someObject.setFoo(myFoo); print(someObject.Foo); // calls someObject.getFoo(); Not only does this look clearer overall, it also allows certain other functionality such as the casting of an object to and from a dictionary (as shown in the JSON example in N9I - 2/2/2010) C# has support for properties but considers them distinct from methods. Java does not include special support, but JavaBeans can mimic properties using an enforced getter/setter naming convention. If a @get method exists without a corresponding @set method, the property is considered read-only. Similarly, if a @set exists without a @get, the property is considered write-only. The method names don't have to follow any convention (although such a convention may be optionally enforced per-project by the compiler), nor do they have to correspond to an actual instance field.