{"id":92,"date":"2017-05-24T00:13:04","date_gmt":"2017-05-24T00:13:04","guid":{"rendered":"https:\/\/blog.johnny-lin.com\/?p=92"},"modified":"2017-05-24T00:13:04","modified_gmt":"2017-05-24T00:13:04","slug":"advice-to-beginning-programmers-who-are-being-required-to-write-comments","status":"publish","type":"post","link":"https:\/\/blog.johnny-lin.com\/?p=92","title":{"rendered":"Advice to Beginning Programmers Who Are Being Required to Write Comments"},"content":{"rendered":"<p>Students in introductory programming courses sometimes feel, &#8220;What&#8217;s the use in commenting?  The important part is getting the program to run.&#8221;  Some students also feel, &#8220;Adding too many comments clutters the code.&#8221;  As a result, there&#8217;s a tendency to avoid commenting or to do the minimum required.<\/p>\n<p>Commenting, however, is a vital part of programming, as commenting is what makes your code useful to others (including yourself a month later).  If you don&#8217;t comment your code, no one else can pick up your code and understand it.  Think of it this way.  If a company hires you to write some code and you leave the company after writing it, if you didn&#8217;t comment your code, how will your replacement understand what you did?  And if your replacement has to rewrite your code because no one can understand it, didn&#8217;t your company just waste its money on your salary?  As a result, no software development company will let someone contribute code that is poorly documented.<\/p>\n<p>That being said, I admit you can overcomment.  Especially when we&#8217;re first learning how to comment, we will tend to provide more details than are necessary.  Still, if you&#8217;re just starting to learn how to program, I&#8217;d encourage you to overcomment rather than undercomment.  At this stage, you need to get into the <i>habit<\/i> of writing comments.  At this stage, the only way to do so is to write more than less.  As you gain more experience in programming, you&#8217;ll get a better sense of what needs to be included and what doesn&#8217;t.  But you can&#8217;t get to that stage if you scrimp on commenting now.<\/p>\n<p>It&#8217;s like learning to write essays.  As a second-grader, when your teacher asked you to write about your favorite pet or what you did over Spring Break, they didn&#8217;t say, &#8220;make sure you only use active voice and be as concise as possible.&#8221;  No, they just wanted you to write as much as you could.  Only later in school did your teachers say, &#8220;be concise, etc.&#8221;  The same thing is true with comments.  At this point, you need to create the habit of commenting, even if you don&#8217;t want to and feel it&#8217;s a waste of time.  Describe what goes into a method, what comes out, the state of the program going in, the state coming out, and what gets changed and how.  If you feel you&#8217;re saying too much, that&#8217;s okay.  Later on, you&#8217;ll learn about what to leave out.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Students in introductory programming courses sometimes feel, &#8220;What&#8217;s the use in commenting? The important part is getting the program to run.&#8221; Some students also feel, &#8220;Adding too many comments clutters the code.&#8221; As a result, there&#8217;s a tendency to avoid commenting or to do the minimum required. Commenting, however, is a vital part of programming, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-92","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=\/wp\/v2\/posts\/92","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=92"}],"version-history":[{"count":5,"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=\/wp\/v2\/posts\/92\/revisions"}],"predecessor-version":[{"id":97,"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=\/wp\/v2\/posts\/92\/revisions\/97"}],"wp:attachment":[{"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}