OutSystems: A Good Example!

OutSystems is an extraordinary platform (made in Portugal). If you Reverse Engineer their code, you can see some really amazing uses of the .NET capabilities (even WeakReferences and the idea of WeakDelegates). Pretty cool.

Here’s a good example:

Converting a string value to a decimal can be done using an OutSystems Built-in function just like below:

But, as you can see in the debugger, converting 223,6 to a decimal goes wrong. Why? Well, if you reverse engineer the code from the OutSystems Platform you end up with the TextToDecimal function:

They use the “long version” of the Decimal.TryParse method. And that’s the good example. By using it, they made the TextToDecimal CultureInvariant. That is, not dependent on Machine configuration. It’s culture-insensitive. So, invoking the reverse engineered method actually yields similar result as expected. The “dot” version converts, the one with the comma doesn’t:

Now, my machine’s current culture is Portuguese:

So, using the short version of Decimal.TryParse doesn’t behave as the above:

As you can see, it’s the opposite of the first version presented above. This is because my current NumberInfo understands the comma (,) as the decimal separator.

And according to the MSDN documentation, when using the no culture constructor, the CultureInfo (and NumberInfo) defaults to the CurrentInfo:

“Parameter ‘s’ is parsed using the formatting information in a NumberFormatInfo object initialized for the current system culture. For more information, see CurrentInfo.

This second version represents problems. Imagine your machine is pt-PT but the production environment is en-US. Bad out come.

Extra point to OutSystems. A case of good development.

Originally published at www.cesarafonso.pt on April 11, 2014.