Page 1 of 1

Automatic Type Conversion

PostPosted: Sun Jul 19, 2009 9:35 pm
by asyed94
I am new to cobra and trying to learn it by writing some simple programs.

While writing this program I noticed that Cobra does not seem to have automatic type conversion.

Code: Select all
class MainProg
   def main is shared
      print 'What is your age?'
      age = Console.readLine
      yob = 2009 - int.parse(age)
      print 'You were born in [yob].'


It would be nice if I didn't have to do int.parse(age). Are there any plans to add automatic type conversion to Cobra in the future; similar to what Perl and PHP have?

http://www.brainbell.com/tutors/php/php ... rsion.html

Or is something like this not possible for Cobra?

Re: Automatic Type Conversion

PostPosted: Mon Jul 20, 2009 3:09 am
by Charles
No, Cobra does not take the approach that Perl does. Things are more strongly typed which results in better error checking at the expense of having to call .parse and such yourself.

Btw Cobra no longer require "is shared" on "def main". Without it, Cobra will automatically instantiate your class and invoke its .main method. I'll update the docs on the site after the next release.