{"id":1060,"date":"2021-02-07T15:31:00","date_gmt":"2021-02-07T22:31:00","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=1060"},"modified":"2021-02-03T15:03:11","modified_gmt":"2021-02-03T22:03:11","slug":"lying-to-the-compiler","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2021\/02\/07\/lying-to-the-compiler\/","title":{"rendered":"Lying to the compiler .. and why it doesnt matter"},"content":{"rendered":"\n<p>If you&#8217;re like some coders you like to have &#8220;clean&#8221; compiles<\/p>\n\n\n\n<p>No warnings. No errors. Nothing.<\/p>\n\n\n\n<p>So when a new one does popup you can inspect it, fix it, and return to a pristine state. Its one way to make sure new issues dont crop up very earliy in your work cycle.<\/p>\n\n\n\n<p>Often you get a lot of &#8220;Unused event parameter&#8221; or &#8220;Unused method parameter&#8221; warnings.<\/p>\n\n\n\n<p>And it can be tedious to go back and insert a pile of #Pragma Unused for each one.<\/p>\n\n\n\n<p>But did you know that you could just write those pragmas right at the outset and tell the compiler that every parameter will be unused ? And that it really wont matter ?<\/p>\n\n\n\n<p>Suppose you write a new method like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Sub foo( bar as integer, baz as color, foobar as string)\nEnd Sub<\/code><\/pre>\n\n\n\n<p>If you now do a check project you will get warnings that the parameters are unused<\/p>\n\n\n\n<p>So if you dutifully enter<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Pragma unused bar\n#Pragma unused baz\n#Pragma unused foobar<\/code><\/pre>\n\n\n\n<p>and redo your check and things are clean again. Now, what if you alter the code to actually use one of those parameters ? Do you need to remove the #pragma ? Doesn&#8217;t that #pragma flag the variable as &#8220;unused&#8221; in a way the compiler will now complain about you saying it was unused but you&#8217;ve now gone &amp; used it ?<\/p>\n\n\n\n<p>In fact the answer is no &#8211; what that pragma does is mark that variable as USED so the compiler will stop complaining about it being unused. (Cute isnt it ?)<\/p>\n\n\n\n<p>You can leave those pragmas in place and use the variable and NOT mess up anything.<\/p>\n\n\n\n<p>So you might consider writing the pragmas at the time you implement the event or method and never get warnings about unused parameters ever again \ud83d\ude42<\/p>\n\n\n\n<p>Or just turn those warnings off \ud83d\ude42<\/p>\n\n\n\n<p>Enjoy !<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re like some coders you like to have &#8220;clean&#8221; compiles No warnings. No errors. Nothing. So when a new one does popup you can inspect it, fix it, and return to a pristine state. Its one way to make sure new issues dont crop up very earliy in your work cycle. Often you get &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2021\/02\/07\/lying-to-the-compiler\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Lying to the compiler .. and why it doesnt matter&#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-1060","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\/1060","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=1060"}],"version-history":[{"count":3,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1060\/revisions"}],"predecessor-version":[{"id":1064,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1060\/revisions\/1064"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=1060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=1060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=1060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}