Convert To or Convert From ?

A while back I started thinking that some of the new style Xojo is using is awkward but it never really struck me why it felt that way.

After working with new releases for a while I know what I find strange.

Sometimes you tell an instance to do something.

var someInteger as Integer
var s as string
s = someInteger.ToString

for instance tells out integer instance someInteger to convert itself to a string. THe style is very much object verb.

Except when its not

var someStringArray() as String
var s as string
s = someStringArray.ToString // NOPE - this does not compile

No in this case we do not tell our “object” , the array, to convert itself to a string like we do many other things. In this case we have to tell the String “type” to make a string From an Array

Var someStringArray() As String
s = String.FromArray(someStringArray)

Yet there are many other places where ToString does exist. Here’s a handful in the Language reference.

Thats not to say the “From type” conversion doesnt make sense. There are lots of places it does. For things that have constructors i makes sense that the “convert from” method might be a constructor, or maybe a shared factory method that returns a new fully created instance. Or maybe its the operator_convert initializer that can return a fully constructed instance. I had a long discussion with Aaron about whether a constructor vs factory vs operator_convert makes more sense and there are some interesting considerations he brought up but I wont go into those details here. Maybe another post another day.

For intrinsic non-reference types like Integer, string, boolean etc where there is no means to use a constructor the choices are really limited. But even in that case we see that things like booleans, integers, colors etc have both a ToString and FromString – something arrays do not have.

That seems particularly inconsistent with all the efforts Xojo is going to to make the language more consistent.

And now I know why I find it jarring that its missing for arrays to be able to tell them to convert To String.

Later !