Page 1 of 1

pro vs var

PostPosted: Wed Nov 12, 2008 12:53 pm
by mindstormss
with the new pro name from var as type construct, I am wondering why not simply to use var name as type...? Is there any functional difference (implementation is different, sure):
Code: Select all
class Test
   var aString as String = 'testing'
   pro aString2 from var as String
   
   def init
      .aString2 = 'testing2'   #or _aString2 = 'testing2'
   
   def printAll
      print '[.aString], [.aString2]'   #I suppose it could be '[.aString] [_aString2]'
   
class Program
   def main is shared
      t = Test()
      print t.aString
      print t.aString2
      t.printAll
      t.aString = 'hi'
      t.aString2 = 'hi2'
      print t.aString
      print t.aString2
      t.printAll


The only differences seem to be negative on the pro side, in that you can't declare the variable to be something on the same line as the declaration (hence the init...) You could also use _aString2, but it is the same amount of typing as .aString2? Personally I prefer the "." over the _, coming from python :)

Re: pro vs var

PostPosted: Wed Nov 12, 2008 1:27 pm
by Charles
I'm not sure what you're asking here. What does "use var name as type" mean?

.NET has properties which have various advantages:

-- Using "public properties and protected vars" enables you to encapsulate your data for the purposes of object-oriented programming. For example, vars don't let you intercept reads and writes for data validation, data manipulation, etc.

-- You can change the implementation of the property to any kind of code without changing the interface or having to re-compile the programs that use a library. You can't do that with vars.

-- DataGridView, PropertyGrid and other classes automatically look for properties, but not vars.

JVM has properties as well, but they are done more by convention (methods named getFoo/setFoo).

I don't know if this helps answer your question. If not, please clarify.