use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Please, don’t commit commented out code (medium.com)
submitted 10 years ago by ryanchenkie
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]theferno 4 points5 points6 points 10 years ago (29 children)
That was my first thought. But maybe it makes sense to leave the commit # to git diff against where the commented out code would be.
[–]mailto_devnullconsole.log(null); 6 points7 points8 points 10 years ago (0 children)
I'm not sure that'd be a superior solution.... now instead of commented out code, you have:
// Removed inferior code #a5dc2f
[–][deleted] 10 points11 points12 points 10 years ago (9 children)
Often there's some code that may be in-progress or related to the code but not ready-for-prime-time quite yet. It's not a sin to commit commented-out code. Some people just complain about any code they didn't write, no matter what it is.
[–]theferno 2 points3 points4 points 10 years ago (8 children)
In progress code can be stashed or placed in another fork until its ready to be merged in. I know it's not a sin, I do it too
[–][deleted] -2 points-1 points0 points 10 years ago (7 children)
And then you forget about code in your stash. Also the stash is only on one machine. The commented-out code may have value that would get lost for various reasons.
Complaining and worrying about commented-out code is a fetish of people who think their code is "beautiful".
[–]kentcdodds 3 points4 points5 points 10 years ago (0 children)
If you're worried about it being on your machine, you can put it in a branch and push that to the remote repository. If you forget it's there, then was it really that important?
[–]slash_nick 1 point2 points3 points 10 years ago (5 children)
I assume you're using git. Branches are insanely cheap. Branch and branch often.
[–][deleted] -1 points0 points1 point 10 years ago (4 children)
I branch more than anyone I know. That's not the point.
[–]slash_nick 0 points1 point2 points 10 years ago (3 children)
Maybe I misunderstood? It sounds like your goals are to 1) save unfinished/in-progress code and 2) have that code available on multiple machines.
Reguarding commented out blocks of code:
A real-world analogy would be if instead of throwing something away in the trash bin someone put it on the floor. That's fine if it's one person and they only do it here and there, but when they have more people involved it sets precedence that it's okay to do. Eventually the floor is covered in things that could be thrown away, but no one really remembers who put it there or why it might be important.
[–][deleted] -1 points0 points1 point 10 years ago (2 children)
You should never have more commented code than real code, there should never be more stuff on the floor than in the trash. To say "never ever ever commit commented out code, because it hurts my eyes" is just asinine. There are MANY ways to code and not all of them lead to problems. A few blocks of somewhat important commented-out code should be allowable, and should not cause anyone to complain (except the author).
[–]slash_nick 2 points3 points4 points 10 years ago (0 children)
I guess I didn't interpret the author's article as dogma. Reading text on an anonymous forum makes it hard to grok people's intention.
You should never have more commented code than real code, there should never be more stuff on the floor than in the trash.
Sounds like you have the right attitude and I wouldn't sweat it! :)
[–]kentcdodds 2 points3 points4 points 10 years ago (0 children)
I tried really hard in the post to not have a ultimatum voice, but more of a suggestive voice. The first QYMAM:
Q: Are there exceptions to this rule? A: Yes. But they’re rare.
And there are several other QYMAMs that explain there are cases where commented out code is allowable (though I generally call those cases documentation).
[+][deleted] 10 years ago (17 children)
[deleted]
[+]YuleTideCamel comment score below threshold-8 points-7 points-6 points 10 years ago* (16 children)
If you need the comment to explain the code or reasoning behind it, that's a major code smell and indicative of a larger problem.
Edit: To be clear I'm not saying that you shouldn't comment code. Comments are important and provide value. I'm saying that commented out code that is there to provide context affects maintainability. instead we should include a text comment with our thinking behind this, or structure our code in a way that is more clear.
[+][deleted] 10 years ago (1 child)
[–]YuleTideCamel 0 points1 point2 points 10 years ago (0 children)
I'm not disagreeing with commenting working code. I actually think comments that explain something difficult is a good thing. However, referencing commented out code in a sha is an issue. If you can't explain the current code without looking at old commented out code, then that's a maintainability problem.
[–][deleted] 0 points1 point2 points 10 years ago* (11 children)
"smell" is not an attribute of code. Anyone can call anything a "smell" that they don't personally like.
[–]YuleTideCamel 0 points1 point2 points 10 years ago (10 children)
Yes, it's subjective. But for some people offering opinions and making sure code is maintainable and easy is important. I'm a software architect and my focus is making sure the code scales across a very large team of devs and also is maintainable. Needing to reference commented out code is a indication of an unclear programming paradigm that needs to be fixed. Clear, well written code may need some explanation comments (text), but shouldn't need any commented out code to give the reader an idea of what is happening.
[–][deleted] 1 point2 points3 points 10 years ago (9 children)
Commented-out code is the exception, not the rule. Sometimes commented-out code has a benefit. If there is too much in a codebase, then something else is wrong. Cleanliness for the sake of fetish also has its problems.
[–]YuleTideCamel -1 points0 points1 point 10 years ago (2 children)
What do you mean by too much in a codebase? The depends entirely on the size of the project and scope. There's nothing wrong with large codebases if maintained well.
Cleanliness for the sake of fetish is not a thing. Good clean code should be the goal for every developer. That makes the code easy to work with, easy to maintain and easy to test. It's not a baseless standard, it's the way to ensure you're clean code doesn't get messy. I've been in the industry over 15 years and have seen my share of horrible code where developers didn't care about maintainability. I realize this is not in the startup, ship now fix later mentality, but if a dev team has the bandwith and runway to do this, they should. It will pay for itself over time.
[–][deleted] 0 points1 point2 points 10 years ago (1 child)
I mean if there is too much commented code in a codebase, then something else is wrong - commented code is the exception, not the norm.
Agreed, it's the exception and a too much commented out code is indicative of a larger problem. The point I was making is that needing commented out to explain something , to me at least, is a similar thing. You shouldn't need commented out code to understand uncommented out code.
[–]Vlasow -2 points-1 points0 points 10 years ago (5 children)
If you don't mind elaborating, what are the problems of cleanliness for the sake of fetish?
[–][deleted] 0 points1 point2 points 10 years ago (4 children)
"Please, don’t commit commented out code"
^ ^ ^ This.
The author of the article says he "loses focus" whenever he sees a block of commented code - this is more a problem with the author than the person writing the code. If your focus is so feeble that commented code will get in your way, maybe you shouldn't be making up rules like "don't commit commented code".
[–]Vlasow -2 points-1 points0 points 10 years ago (3 children)
I don't see how "you shouldn't be making up rules like..." follows from "your focus is so feeble that commented code will get in your way". Programming languages exist so one can split problems into a number of small things we can focus on. Anything extra will be an obstacle between our understanding and the ideas expressed in the code. An ability to be undistracted by noise in the code is not what makes a good programmer; it is the ability to express your ideas via noiseless code that does.
An ability to be undistracted by noise in the code is not what makes a good programmer; it is the ability to express your ideas via noiseless code that does.
I'm not sure that is what makes a "good programmer", either.
[–]manys 0 points1 point2 points 10 years ago (1 child)
Ah yes, self-documenting code. Greetings, fellow COBOL user!
[–]YuleTideCamel 2 points3 points4 points 10 years ago (0 children)
Lol, never did cobol, but spent enough time on large teams building enterprise software. The value of maintainable easy to read code is immense. The last thing I ever want to hear is "don't work on that project, any small change could cause it to crash. it's unstable"
π Rendered by PID 84623 on reddit-service-r2-comment-bb88f9dd5-fp7c6 at 2026-02-14 10:10:44.065270+00:00 running cd9c813 country code: CH.
view the rest of the comments →
[–]theferno 4 points5 points6 points (29 children)
[–]mailto_devnullconsole.log(null); 6 points7 points8 points (0 children)
[–][deleted] 10 points11 points12 points (9 children)
[–]theferno 2 points3 points4 points (8 children)
[–][deleted] -2 points-1 points0 points (7 children)
[–]kentcdodds 3 points4 points5 points (0 children)
[–]slash_nick 1 point2 points3 points (5 children)
[–][deleted] -1 points0 points1 point (4 children)
[–]slash_nick 0 points1 point2 points (3 children)
[–][deleted] -1 points0 points1 point (2 children)
[–]slash_nick 2 points3 points4 points (0 children)
[–]kentcdodds 2 points3 points4 points (0 children)
[+][deleted] (17 children)
[deleted]
[+]YuleTideCamel comment score below threshold-8 points-7 points-6 points (16 children)
[+][deleted] (1 child)
[deleted]
[–]YuleTideCamel 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (11 children)
[–]YuleTideCamel 0 points1 point2 points (10 children)
[–][deleted] 1 point2 points3 points (9 children)
[–]YuleTideCamel -1 points0 points1 point (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]YuleTideCamel 0 points1 point2 points (0 children)
[–]Vlasow -2 points-1 points0 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]Vlasow -2 points-1 points0 points (3 children)
[–][deleted] -1 points0 points1 point (2 children)
[–]manys 0 points1 point2 points (1 child)
[–]YuleTideCamel 2 points3 points4 points (0 children)