Forums

pro vs var

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

pro vs var

Postby mindstormss » Wed Nov 12, 2008 12:53 pm

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 :)
Eat a live toad the first thing in the morning and nothing worse will happen to you the rest of the day.
mindstormss
 
Posts: 8

Re: pro vs var

Postby Charles » Wed Nov 12, 2008 1:27 pm

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 144 guests

cron