{"id":1109,"date":"2021-04-02T16:35:00","date_gmt":"2021-04-02T22:35:00","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=1109"},"modified":"2021-03-25T16:59:38","modified_gmt":"2021-03-25T22:59:38","slug":"a-lack-of-symmetry","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2021\/04\/02\/a-lack-of-symmetry\/","title":{"rendered":"A lack of symmetry"},"content":{"rendered":"\n<p><a href=\"https:\/\/forum.xojo.com\/t\/problems-with-nt-boolean-tostring-tbln\/62233\">This thread<\/a> illustrates some of the confusion people have with API 2<\/p>\n\n\n\n<p>The documentation doesn&#8217;t help clear it up either since it says, quite clearly, that there seems to be a Boolean.ToString method.<\/p>\n\n\n\n<p>I know this isn&#8217;t whats meant, but the writer of that thread obviously doesn&#8217;t.<\/p>\n\n\n\n<p>Right now code has to look like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dim b as boolean = Boolean.FromString(\"true)\ndim s as string = b.ToString<\/code><\/pre>\n\n\n\n<p>One line uses a parameter and the other doesn&#8217;t. One is defined in a module named for a type and the other isnt. Its a little unsymmetrical and hard to get used to because its not consistent. This confusion is what spawned the original posters post on the forum.<\/p>\n\n\n\n<p>One way to fix this is to just tell people their code is wrong. Thats not likely to garner a lot of &#8220;Gee thanks&#8221; kind of responses though.<\/p>\n\n\n\n<p>One way to fix this might be to just add operator_convert method to all the data types. But this then smacks of &#8220;variant magic&#8221; and isnt quite as explicit or obvious. But you could do something like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dim b as boolean = \"true\" \ndim s as string = b<\/code><\/pre>\n\n\n\n<p>Another might be to add to the Boolean module, a &#8220;ToString&#8221; method that takes a boolean as a parameter and returns a string.<\/p>\n\n\n\n<p>Then code could look like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dim b as boolean = Boolean.FromString(\"true\")\ndim s as string = Boolean.ToString(b)<\/code><\/pre>\n\n\n\n<p>which also improves symmetry &#8211; except now you use a TO method and FROM method on one data type which is a bit verbose and not quite symmetrical. As well do you then need to add a TO and FROM method to every data type ? Thats a big pile of TO and FROM methods in every data type module.<\/p>\n\n\n\n<p>Maybe this could be improved by putting additional FROM conversion methods in for String, Boolean, and the other data types. Then the code might look like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dim b as boolean = Boolean.FromString(\"true\")\ndim s as string = String.FromBoolean(b)<\/code><\/pre>\n\n\n\n<p>That way at least the conversions are more consistent and you use the data type name as the prefix to know what the conversion will return. A String.From will give you back a string from the passed type. A Boolean.From method will give you a boolean. And if all you have is From methods then its 100% consistent. Everything JUST has Convert From style methods.<\/p>\n\n\n\n<p>Either way the current set up has issues because it isn&#8217;t consistent and it apparently confuses the very people who it was intended to help.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This thread illustrates some of the confusion people have with API 2 The documentation doesn&#8217;t help clear it up either since it says, quite clearly, that there seems to be a Boolean.ToString method. I know this isn&#8217;t whats meant, but the writer of that thread obviously doesn&#8217;t. Right now code has to look like One &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2021\/04\/02\/a-lack-of-symmetry\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;A lack of symmetry&#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_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1109","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\/1109","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=1109"}],"version-history":[{"count":5,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1109\/revisions"}],"predecessor-version":[{"id":1114,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1109\/revisions\/1114"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=1109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=1109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=1109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}