5 ms·
"Don’t leave unused code hanging around because it might be useful someday. If it’s not being used right now, remove it, because even just sitting there it’s co
by awolf 17y ago
"Don’t leave unused code hanging around because it might be useful someday. If it’s not being used right now, remove it, because even just sitting there it’s costing you."
Couldn't agree more - every extra line makes the source code that much harder to wrap your brain around.
If I glance at a section in my code and can't instantly grasp what it is doing and how it fits into the bigger picture then I know I still have refactoring to do.
- DarkShikari 17y agoAnd version control keeps it around for you anyways. I can't even count the number of times I've heard "but this code will be useful if/when we add support for feature X" used to justify hundreds or even thousands of lines of ifdeffed-out cruft.
- sunkencity 17y agoI worked with someone who never threw old code away. It was amusingly difficult to try to understand what his code did. Typically shitloads of php files that didn't do anything and in the files that actually did something stuff like if (false) { ... large incomprehensible code block .. } was common. Why comment out stuff when you can just disable it programmatically?
- davidw 17y agoI did some work at a place where they had a PHP class called something like "foobar_2004_08". Given that it was 2006, I asked about axing it, but was told it was still in use. Shudder
- theli0nheart 17y agoUgh, makes me sick to my stomach.
- scotty79 17y agoThe cause could be that inside the block there were already the /* */ comments, and editor did not have single keystroke option to add // at the beginning of each selected line.
- sunkencity 17y agono. he used Eclipse. Apple-7 would have worked.
- scotty79 17y agoOk. So I have another theory. In place of false there was previously some ugly condition and he wanted get rid of the things that were done on this condition with minimal necessary effort hoping that someone in the future with more time (maybe even himself) will clean that up since doing cleanup in such case is not hard thing to do.
- ajb 17y agoThere is actually a reason for doing that, as opposed to commenting it out - at least in compiled languages, the compiler will complain if code changes elsewhere conflict with it, so it doesn't bitrot as fast.
- fogus 17y agoYes, version control does keep it around for you, but often it is not the easiest thing to associate some piece of code with a repo version. I am not advocating keeping chunks of commented-out code around; just saying that I have yet to find an optimal solution to the other side of the problem either.
- cema 17y agoAn easy solution is to split it off to an "Unused" pseudoproject in the source control system. This avoids archeology on historical versions.
- joeyo 17y ago> This avoids archeology on historical versions. It's not really your main point, but the idea of revision control archeology is a really a great analogy.
- holygoat 17y agoI favor a 'scratch' or 'junk' dir in each project. Source that I know I don't need now, but want to keep around. grepping for terms will often find a chunk of code I wrote that nearly solves a new problem. Version control is not so easy to search, particularly if you're looking for a utility that you think is live in the project.
- cema 17y agoYes, grepping a folder is easy. Of course, you can always update it from the source control database. :-)
- InclinedPlane 17y agoOn the next episode of Code Hoarders...