{"id":108482,"date":"2023-07-25T07:00:00","date_gmt":"2023-07-25T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=108482"},"modified":"2023-07-25T07:07:11","modified_gmt":"2023-07-25T14:07:11","slug":"20230725-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20230725-00\/?p=108482","title":{"rendered":"Before you try to do something, make sure you can do nothing"},"content":{"rendered":"<p>When building a new thing, a good first step is to build a thing that <i>does nothing<\/i>. That way, you at least know you are starting from a good place. If I&#8217;m building a component that performs an action, I&#8217;ll probably do it in these steps:<\/p>\n<ul>\n<li>Step zero is to write a standalone program to perform the action. This ensures that the action is even possible.<\/li>\n<li>Once I have working code to perform the action, I write a component that <i>doesn&#8217;t<\/i> perform an action. That at least makes sure I know how to build a component.<\/li>\n<li>Next, I register the component for the action, but have the <code>Invoke<\/code> method merely print the message &#8220;Yay!&#8221; to the debugger without doing anything else. This makes sure I know how to get the component to run at the proper time.<\/li>\n<li>Next, I fill in the <code>Invoke<\/code> method with enough code to identify what action to perform and which object to perform it on, print that information to the debugger, and return without actually performing the action. This makes sure I can identify which action is supposed to be done.<\/li>\n<li>Finally, I fill in the rest of the <code>Invoke<\/code> method to perform the action on the desired object. For this, I can copy\/paste the already-debugged code from step zero.<\/li>\n<\/ul>\n<p>Too often, I see relatively inexperienced developers dive in and start writing a big complex thing: Then they can&#8217;t even get it to compile because it&#8217;s so big and complex. They ask for help, saying, &#8220;I&#8217;m having trouble with this one line of code,&#8221; but as you study what they have written, you realize that this one line of code is hardly the problem. The program hasn&#8217;t even gotten to the point where it can comprehend the possibility of executing that line of code. I mutter to myself, &#8220;How did you let it get this bad?&#8221;<\/p>\n<p>Start with something that does nothing. Make sure you can do nothing successfully. Only then should you start making changes so it starts doing something. That way, you know that any problems you have are related to your attempts to do something.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you can&#8217;t do nothing, then don&#8217;t expect to be able to do something.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25,26],"class_list":["post-108482","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code","tag-other"],"acf":[],"blog_post_summary":"<p>If you can&#8217;t do nothing, then don&#8217;t expect to be able to do something.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/108482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=108482"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/108482\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=108482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=108482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=108482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}