Forums

Automatic Type Conversion

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

Automatic Type Conversion

Postby asyed94 » Sun Jul 19, 2009 9:35 pm

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?
asyed94
 
Posts: 1

Re: Automatic Type Conversion

Postby Charles » Mon Jul 20, 2009 3:09 am

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


Return to Discussion

Who is online

Users browsing this forum: No registered users and 50 guests