• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

I Like Kill Nerds

The blog of Australian Front End / Aurelia Javascript Developer & brewing aficionado Dwayne Charrington // Aurelia.io Core Team member.

  • Home
  • Aurelia 2
  • Aurelia 1
  • About
  • Aurelia 2 Consulting/Freelance Work

Committing Commented Out Code

Opinion · October 28, 2015

I have been loving Medium lately. Since its new version launched, I have been more engaged in its content and reading some great articles.

This morning I came across an article title Please, don’t commit commented out code – based on the title, I am sure you can work out what the article is about.

I think many of us have been guilty of committing commented out code into the main source repository. It happens, sometimes intentionally and sometimes unintentionally.

In my opinion sometimes committing commented out code is warranted, especially during the early development phase. But only for really limited scenarios like debug lines, most of the time even debug lines are not justification enough (but I have done it many times).

In the article Kent seems to use examples of large chunks of code being commented out, one such example is:

function foo(bar) {
  const baz = bar(false)
  // we no longer do this for some good reason
  // if (baz === 'foobar') {
  // return baz
  // } else {
  // return bar.foobar()
  // }
  return baz
}

I agree that under no circumstance should a developer do this. It is a dogs breakfast of mess and dispair. A little further down Kent suggests that we use git diff to get back old bits of code that we needed.

I have encountered many developers who don’t know how Git well enough to do a git diff on a file to get back existing changes. It seems many developers these days rely on tools like Sourcetree to work with Git and for most purposes that is fine, but I think knowing some of the command line commands is handy.

Git clients are not the be all and end all. Somewhere along the line you need the command line. Interestingly in the comments on the Reddit submission, some people are actually defending committing commented out code into the repository.

It becomes increasingly obvious many developers who decide to commit commented out code are not aware of git diff or they don’t know how to use it, so they pick the lazy option and take the easy way out. Instead of learning how real source control works, commenting out code becomes the preferred option.

There is rarely a good reason to commit commented out code. Either you learn how to use Git properly if you’re scared of diffing a file or you quit development until you learn how source code management in the real world works.

Dwayne

Leave a Reply Cancel reply

0 Comments
Inline Feedbacks
View all comments

Primary Sidebar

Popular

  • I Joined Truth Social Using a VPN and Editing Some HTML to Bypass the Phone Verification
  • Testing Event Listeners In Jest (Without Using A Library)
  • How To Get The Hash of A File In Node.js
  • Thoughts on the Flipper Zero
  • Waiting for an Element to Exist With JavaScript
  • How To Paginate An Array In Javascript
  • How To Mock uuid In Jest
  • How To Decompile And Compile Android APK's On A Mac Using Apktool
  • How To Get Last 4 Digits of A Credit Card Number in Javascript
  • Wild Natural Deodorant Review

Recent Comments

  • CJ on Microsoft Modern Wireless Headset Review
  • Dwayne on Microsoft Modern Wireless Headset Review
  • CJ on Microsoft Modern Wireless Headset Review
  • john on Microsoft Modern Wireless Headset Review
  • Dwayne on Why You Should Be Using globalThis Instead of Window In Your Javascript Code

Copyright © 2023 · Dwayne Charrington · Log in

wpDiscuz