DEV Community

CodingBlocks

Episode 49 – Clean Code – Comments Are Lies

This week, Michael fails geography, Allen introduces us to Croom, and Joe has to potty as we head into our third installment of the Clean Code series.

Want to be part of our Slack community? Sign up @ http://www.codingblocks.net/slack and say “hi”!

Join our Slack!

Link to Episode 49’s Full Show Notes

http://www.codingblocks.net/episode49

Survey

#yop-poll-container-25_yp581ff0a0acd58 { width: 600px; background:#fff; padding:10px; color:#555; overflow:hidden; font-size:12px; } #yop-poll-container-25_yp581ff0a0acd58 input[type='text'] { margin:0px 0px 5px 0px; padding:2%; width:96%; text-indent:2%; font-size:12px; } .yop-poll-name-25_yp581ff0a0acd58 { font-size:14px; font-weight:bold; } #yop-poll-questions-container-25_yp581ff0a0acd58 { font-size:14px; margin:5px 0px; } .yop-poll-question-container-25_yp581ff0a0acd58 { padding: 2px; } .yop-poll-question-25_yp581ff0a0acd58 { font-style: italic; text-align: center; margin-bottom: 21px; margin-top: -10px; width: 100%; } .yop-poll-answers-25_yp581ff0a0acd58 { } .yop-poll-answers-25_yp581ff0a0acd58 ul { list-style: none outside none; margin: 0; padding: 0; } .yop-poll-li-answer-25_yp581ff0a0acd58 { font-style:normal; margin:0px 0px 10px 0px; padding:0px; font-size:12px; margin-bottom:20px; margin-bottom:20px; } .yop-poll-li-answer-25_yp581ff0a0acd58 input { margin:0px; float:none; } .yop-poll-li-answer-25_yp581ff0a0acd58 label { margin:0px; font-style:normal; font-weight:normal; font-size:12px; float:none; } .yop-poll-results-25_yp581ff0a0acd58 { font-size: 12px; font-style: italic; font-weight: normal; margin-left: 15px; } .yop-poll-customs-25_yp581ff0a0acd58 { } .yop-poll-customs-25_yp581ff0a0acd58 ul { list-style: none outside none; margin: 0; padding: 0; } .yop-poll-li-custom-25_yp581ff0a0acd58 { padding:0px; margin:0px; font-size:14px; } /* Start CAPTCHA div style*/ #yop-poll-captcha-input-div-25_yp581ff0a0acd58 { margin-top:5px; } #yop-poll-captcha-helpers-div-25_yp581ff0a0acd58 { width:30px; float:left; margin-left:5px; height:0px; } #yop-poll-captcha-helpers-div-25_yp581ff0a0acd58 img { margin-bottom:2px; } #yop-poll-captcha-image-div-25_yp581ff0a0acd58 { margin-bottom:5px; } #yop_poll_captcha_image_25_yp581ff0a0acd58 { float:left; } /* End CAPTCHA div style*/ .yop-poll-clear-25_yp581ff0a0acd58 { clear:both; } #yop-poll-vote-25_yp581ff0a0acd58 { } /* Start Result bar*/ .yop-poll-results-bar-25_yp581ff0a0acd58 { background:#f5f5f5; height:10px; } .yop-poll-results-bar-25_yp581ff0a0acd58 div { background:#555; height:10px; } /* End Result bar*/ /* Start Vote Button*/ #yop-poll-vote-25_yp581ff0a0acd58 div#yop-poll-vote-25_yp581ff0a0acd58 button { float:left; } #yop-poll-vote-25_yp581ff0a0acd58 div#yop-poll-results-25_yp581ff0a0acd58 { float: right; margin-bottom: 20px; margin-top: -20px; width: auto; } #yop-poll-vote-25_yp581ff0a0acd58 div#yop-poll-results-25_yp581ff0a0acd58 a { color:#555; text-decoration:underline; font-size:12px; } #yop-poll-vote-25_yp581ff0a0acd58 div#yop-poll-back-25_yp581ff0a0acd58 a { color:#555; text-decoration:underline; font-size:12px; }#yop-poll-vote-25_yp581ff0a0acd58 div#yop-poll-archive-25_yp581ff0a0acd58 a { color:#555; text-decoration:underline; font-size:12px; } #yop-poll-vote-25_yp581ff0a0acd58 div { float:left; width:100%; } /* End Vote Button*/ /* Start Messages*/ #yop-poll-container-error-25_yp581ff0a0acd58 { font-size:12px; font-style:italic; color:red; text-transform:lowercase; margin-bottom:20px; text-align:center; } #yop-poll-container-success-25_yp581ff0a0acd58 { font-size:12px; font-style:italic; color:green; margin-bottom:20px; text-align:center; } /* End Messages*/ .yop-poll-clear-25_yp581ff0a0acd58 { clear: both; }#yop-poll-container-25_yp581ff0a0acd58 img { max-width: 600px; } .yop-poll-forms-display{}
Do you put stickers on your laptop?
  • No. I've got class and I'm an adult. Stickers are for kids.
  • STICKERS!!! STICKERS ALL THE THINGS!!!

News

Stickers! Stickers All the Things!

Want some Coding Blocks stickers? Send us a self-addressed stamped envelope and we’ll send you some of the most amazing stickers you’ve ever seen.

Comments

  • “At best, comments are a necessary evil”
  • “The purpose of a comment is to compensate for our failure to express ourself in code”
  • Try to express yourself in code rather than a comment
  • Comments should be updated as code is updated, but a better use of time would be to make the code itself more expressive
  • Inaccurate comments are worse than no comments at all – they’re lies…misleading
    Comments do NOT make up for bad code
  • If you feel you need to comment the code, it might be a good time to assess whether you should create a new method that will better express what you’re attempting to do
  • “The only good comment is the one you found a way not to write”
  • Copyright and licensing are good uses of comments – they’re usually required
  • These comments should provide a reference to the full body of the license rather than including the text in the comment
  • Another good use shown in the book is showing the expected format of a regular expression
  • Clarifying comment to describe what you’re doing when working with a third party library you cannot change is also useful at times – this can be tricky because you could make bad assumptions and misinform – so take caution
  • TODO – sometimes ok, but don’t want them to litter up your repo
  • Documentation for public API’s – just be careful not to write non-truths here as it’s easy to do if you don’t update your comments as the code changes
  • Most comments are just bad comments…not needed and code should have been changed
  • Took some shots at Javadocs for Tomcat – they were admittedly pretty useless
  • Too easy to write misleading comments – subtle differences can lead people down the wrong path
  • Author generally dislikes commenting of methods – for the fact that they will eventually become misleading if not so at the outset
  • Log journals – used to be useful before source control – now they should be removed – SQL anyone?!
  • Noise – useless, add nothing comments – restating the obvious
  • Comments that complain about things are bad – they should be refactored into useful methods
  • Don’t use a comment when you can use a function or variable
  • Banners – used to identify a section in code – can be useful but also lose effectiveness if overused
  • Don’t put your bylines in the code- let the source control keep track of that for you
  • Do NOT comment out code…delete it – source control will provide you a history
  • HTML Comments in your code should NOT be used…it’s unreadable
  • Only comment on the code right next to the comment – do not make system type of comments as they can quickly become incorrect
  • Don’t write too much information in a comment
  • The comment should be easy to connect to the code it’s describing – if it doesn’t then the comment is worse than useless
  • Function headers – a well named function is better than a comment header
  • Only use Javadocs (or similar) for public API’s – they do more harm than good in private repos

Resources We Like

Of course we’re going to mention Clean Code by Robert C Martin here, right? Yes, yes we are. Want a copy? Comment on this show for your chance to win a copy!

Clean Code

Clean Code

Tip of the Week

  • Add a path to your Git commands to narrow their scope:
    • git status [path]
    • git diff [path]
    • git add [path]
  • http://hyperdev.com – Focus on building your MVP. Not the infrastructure.
  • http://www.codemaid.net/documentation/ – Don’t just read about clean code. Use some tools to keep it clean!

Enjoyed the Show? Tell Everyone!

Do you like us? Pick one:

– Yes
– Of course!
– Um, yeah, but this is weird.

So then you should tell everyone. And I’m mean everyone. And when you’re friends ask what you’re doing? Answer: Coding Blocks! When your boss asks how you’ve suddenly gotten more productive? Answer: Coding Blocks! And when mom asks what you want for dinner? Answer: Tacos! Er, wait. Well, you get the idea. Spread the word.

And by the way, if you haven’t already, head over to www.codingblocks.net/review to leave a review as your digital way of shouting from the roof tops how much you enjoy the show.

Peace, love, and Coding Blocks.

Episode source