{"id":270,"date":"2019-09-04T12:32:36","date_gmt":"2019-09-04T18:32:36","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=270"},"modified":"2019-08-29T12:46:58","modified_gmt":"2019-08-29T18:46:58","slug":"generics","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2019\/09\/04\/generics\/","title":{"rendered":"Generics"},"content":{"rendered":"\n<p>One of the things that Xojo lacks is the notion of generics.<\/p>\n\n\n\n<p>So what are these things and why would they be useful ?<\/p>\n\n\n\n<p>In many programming languages you might want to define a class that behaves like a <a href=\"https:\/\/www.great-white-software.com\/blog\/2019\/08\/06\/interfaces\/\">List<\/a>. But you want to be able to make this generic enough that when you go to use one you can make a List of Strings, a List of Classes, a List of controls etc.<\/p>\n\n\n\n<p>Right now the only way to do this in Xojo is to make all the the parameters and return values be variants in the interface definition. The downside to this is that you lose all compile time type checking and have to rely solely on runtime checks YOU put in the code. <\/p>\n\n\n\n<p>If you could declare a List variable like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Dim myStringList as List&lt;String><\/code><\/pre>\n\n\n\n<p>This would indicate that the list should use String as the &#8220;generic type&#8221; for all the method parameters and return types. The interface declaration might have to change to something like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Interface List&lt;Type>\n\n  Sub AddRow(ParamArray values() as &lt;Type>)\n  End Sub\n  \n  Sub AddRowAt(ParamArray values() as &lt;Type>, zeroBasedInxed as integer)\n  End Sub\n  \n  Sub FirstRowIndex() as integer\n  End Sub\n  \n  Sub LastAddedRowIndex() as integer\n  End Sub\n  \n  Sub LastRowIndex() as integer\n  End Sub\n  \n  Sub RemoveAllRows()\n  End Sub\n  \n  Sub RemoveRowAt(zeroBasedIndex as integer)\n  End Sub\n  \n  Sub RowCount() as integer\n  End Sub\n  \n  Sub RowTag() as Variant\n  End Sub\n  \n  Sub RowTagAt(zeroBasedIndex as integer) as &lt;Type>\n  End Sub\n  \n  Sub RowValue() as &lt;Type>\n  End Sub\n  \n  Sub RowValueAt(zeroBasedIndex as integer) as &lt;Type>\n  End Sub\n  \n  Sub SelectedRowCount() as Integer\n  End Sub\n  \n  Sub SelectedRowIndex() as integer\n  End Sub\nEnd Interface<\/code><\/pre>\n\n\n\n<p>And now we have a generic interface AND a way to define a list that will, at compile time, have a specific and known type so the compiler can detect any incompatible type errors.<\/p>\n\n\n\n<p>This would make interfaces even more useful than they are now.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the things that Xojo lacks is the notion of generics. So what are these things and why would they be useful ? In many programming languages you might want to define a class that behaves like a List. But you want to be able to make this generic enough that when you go &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2019\/09\/04\/generics\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Generics&#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":[3],"class_list":["post-270","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-xojo"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/270","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=270"}],"version-history":[{"count":1,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/270\/revisions"}],"predecessor-version":[{"id":271,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/270\/revisions\/271"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}