Property syntax

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Re: Property syntax

Postby hopscc » Sat Jun 08, 2013 4:25 am

Not sure those are good examples of implicit insertion since they are built into the framework rather than the language and (wrt inheritance and initializers) there is still an indication of 'something extra' happening (inherits and cue init).

As earlier, I dont mind so long as there still exists the capability of putting 'from var' in if desired.

Take the balance example above - doesnt need or use a backing variable
get balance as number
bal = 0.0
for order in orders, bal += order.bal
return bal

If I understand the proposal correctly will still get one inserted though not needed or used

result as if had written:

# implicit backing variable inserted (though unneeded)
var _balance as Number

get balance as number
bal = 0.0
for order in orders, bal += order.bal
return bal

with the explicit 'from var', its existence serves as an indicator that cobra is directed to use/create backing variable.
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Property syntax

Postby Charles » Sat Jun 08, 2013 11:26 am

In this example an initializer is created even though none is declared and there is no "inherits" or "cue init":
class X

def hello
print 'hello'

I'm not sure what you meant by "built into the framework". If you are referring to C#, that's their language and compiler; the CLR run-time doesn't do this. Also, Cobra will do it for all initializers, matching their arg list. C# doesn't match anything; it just adds one parameterless constructor.

Regarding your balance example, there would be no _balance member created because you implemented the method yourself. The backing var would only be created when you did not provide an implementation. I suppose another way to state it would be:

Cobra can provide a default implementation for properties, which is a backing var of the same type. Any explicit implementation replaces this and completely controlled by the programmer.
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 10 guests