{"id":1065,"date":"2021-02-09T19:11:00","date_gmt":"2021-02-10T02:11:00","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=1065"},"modified":"2021-02-03T15:03:21","modified_gmt":"2021-02-03T22:03:21","slug":"convert-to-or-convert-from","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2021\/02\/09\/convert-to-or-convert-from\/","title":{"rendered":"Convert To or Convert From ?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After working with new releases for a while I know what I find strange.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes you tell an instance to do something.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var someInteger as Integer\nvar s as string\ns = someInteger.ToString<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">for instance tells out integer instance <code>someInteger<\/code> to convert itself to a string. THe style is very much <code>object verb<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Except when its not<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var someStringArray() as String\nvar s as string\ns = someStringArray.ToString \/\/ NOPE - this does not compile<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">No in this case we do not tell our &#8220;object&#8221; , the array, to convert itself to a string like we do many other things. In this case we have to tell the String &#8220;type&#8221; to make a string From an Array<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Var someStringArray() As String\ns = String.FromArray(someStringArray)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Yet there are many other places where ToString does exist. Here&#8217;s a handful in the Language reference.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"225\" height=\"237\" src=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-25-at-7.18.19-PM.png?resize=225%2C237&#038;ssl=1\" alt=\"\" class=\"wp-image-1066\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Thats not to say the &#8220;From type&#8221; conversion doesnt make sense. There are lots of places it does. For things that have constructors i makes sense that the &#8220;convert from&#8221; 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.<br><br>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 &#8211; something arrays do not have. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That seems particularly inconsistent with all the efforts Xojo is going to to make the language more consistent.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And now I know why I find it jarring that its missing for arrays to be able to tell them to convert To String.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Later !<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. for instance tells out integer &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2021\/02\/09\/convert-to-or-convert-from\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Convert To or Convert From ?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-1065","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1065","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/comments?post=1065"}],"version-history":[{"count":1,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1065\/revisions"}],"predecessor-version":[{"id":1067,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1065\/revisions\/1067"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=1065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=1065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=1065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}