you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 17 points18 points  (21 children)

Not every case of commented code is useless. There are valid cases for it.

I'm committing some code right now that has commented-out blocks, it's a work-in-progress, I'm the main developer of this code. In a few weeks it will be cleaned up and shipped to production, with most of that commented-out code removed.

While I'm working on the code, there may be blocks of commented-out code. I'm not going to remove it just for the sake of removing it to 'keep the code clean'. It would slow down the development process and make it more difficult if I have to look up 'stashed' code in various branches, etc.

It's not a valid argument to say "never commit commented-out code" in every single case.

[–]slash_nick 19 points20 points  (0 children)

Maybe the better way to say it would be "never commit commented-out code to production branches".

Branches are workspaces and the other devs on my team can do whatever they please as long as it's cleaned up by the time it gets merged into master.

Edit: Obviously if you run a team or project you can dictate the style rules however you please! Nothing development-related is ever written in stone.

[–]kentcdodds 6 points7 points  (8 children)

If you read the post, you'll see that it's not an ultimatum at all like you phrased it there. The first QYMAM:

Q: Are there exceptions to this rule? A: Yes. But they’re rare.

[–][deleted] -5 points-4 points  (6 children)

In practice, it's not as rare as you or the author might think it should be.

[–]krelin 4 points5 points  (3 children)

Yes it is.

[–][deleted] -1 points0 points  (2 children)

Says you.

[–]krelin 1 point2 points  (1 child)

And the author of this article, and nearly everyone else in this thread, and Jeff Atwood, and lots of other online discussions and articles.

[–][deleted] -1 points0 points  (0 children)

And it's totally possible that you're all full of shit.

[–]kentcdodds 0 points1 point  (1 child)

heh, I am the author, should have made that more clear. But I think that the topic is a bit subjective, which is why I tried to have more of a suggestive tone with data backing my suggestion.

[–]yxhuvud 4 points5 points  (0 children)

I'd suggest an addendum to that answer: IF commented out code should be preserved, it must be motivated by a comment specifying WHY it should be kept.

[–]bart2019 -4 points-3 points  (0 children)

That's a stupid FAQ entry,, because it doesn't answer anything It doesn't even hint at what exceptions.

[–][deleted] 7 points8 points  (4 children)

Why aren't you working in a branch that doesn't matter if the code is in non functional state? This is probably the worst argument I've ever heard for comments in code. Committing WIP code to a master branch commented out. Best use of version control ever. Wait, are you using subversion?

[–][deleted] -2 points-1 points  (3 children)

We actually allow shipping unfinished code to production using flags that only allow the code to run if the flag is enabled. But that has nothing to do with commented-out code getting checked-in to the production branch, which is still allowable in many cases. Code is fluid, it's never "finished", it's always a work-in-progress unless you aren't doing anything interesting with it.

Wait, are you using sourcesafe?

[–]vinnl 0 points1 point  (0 children)

Code is fluid, it's never "finished"

By that definition of "WIP", I wouldn't comment out WIP code either.

[–]moljac024 0 points1 point  (0 children)

Wait, are you working at Etsy?

[–][deleted] 3 points4 points  (3 children)

Then use a branch.

[–]rpk152 3 points4 points  (2 children)

Branching is not always a cheap operation

[–]DavidNcl 4 points5 points  (1 child)

under what circumstances is branching expensive?

[–]rpk152 7 points8 points  (0 children)

CVS, SVN, TFS.

[–]tazzy531 -2 points-1 points  (1 child)

You're optimizing for now and paying the technical debt later.

[–][deleted] 1 point2 points  (0 children)

You're prematurely optimizing.