Discussion: Casting Storm


Hello there, after using Outsystems for almost a year now, I came across the following situation (like, a LOT) when developing:

Having a identifier (let's say, text identifier), i need to compare it with a Integer field, simple right? Err...

SomethingToCompare = TextToInteger(IdentifierToText(MethodThatGivesMeATextIdentifier.Value))

Really? Why can't the IDE simple accept 'SomethingToCompare = MethodThatGivesMeATextIdentifier.Value'. I may guess that when compiling the cast is done only once, so why not let to the compiler make a natural cast? Come on, imaging if on others IDE (Visual Studio, Eclipse, etc) we had cast to everything... 

Currently the platform accepts a Text variable to be assigned with a Integer, but not the other way... Why? Because when casting Integer to Text there is no Exception to be raised? Really?

Hi Mauricio,

Personally, I think it's bad already to have automatic casting from Integer to Text, as it leads to sloppy programming putting numeric values into text and not noticing. I always cast, even if there's autocasting available. The other way around it's even trickier: if automatically casting text to integer, what do you want to happen if the text doesn't contain an integer value? Assign the default value (0), or an generate an Exception? And what do you want to happen when the program encounters something like myInt + myText? Convert integer to text and the result is a string, or convert text to integer and the result is an integer? Autocasting everything to everything becomes messy very quickly, and I'm glad what you suggest is not possible!