Weird. Iâve never had a job which allows commented out code to be committed, and I always flag it when I see it in review.
Iâm not talking about committing commented out code, Iâve specifically mentioned the use case of debugging, prototyping and exploring solutions. You donât commit your testing/prototyping code in general, period.
Avoiding a bad practice in favor of something better is not a âworkaroundâ. Itâs choosing not to be lazy, out of a sense of responsibility to others who may need to deal with your laziness later, and a sense of pride in oneâs workmans hip.
I will go on a side tangent here and rant a bit, but I have absolutely no idea why Zig enforces the style of programming where each little change you make to the code, not matter how inconsequential, must be treated like itâs about to be committed to the NASA codebase running on Voyager II beyond the solar system. Nobody here argues that the rules Zig enforces to the code are bad in the committed, public code. But they absolutely do tank the productivity in this language. People donât want to be lazy, they simply want their tooling to respect their time, and when every time you construct a function, introduce a temporary variable, and now - temporarily disable a block of code - you have to nanny the compiler for things that will likely not even exist in the final result, will have no influence on the resulting quality of the code. The frustration people often describe comes from a waste of time, not being âlazyâ or whatever you want to call it. There are so many possible solutions to control the quality of the code without introducing this silliness in the compiler - ranging from git hooks to only enforcing all of this when compiling in release modes, I just donât get why the developers ignore these?
Conditional compilation as a solution to this problem is the new icing on this cake. Introducing a new comptime variable and a scope, and even a compilation flag (as @tsdtas mentioned), just to emulate Ctrl-/
is absurd. Youâre telling me that some lines are starting with //
may confuse the maintainer, but a piece of dead code that looks identical to the alive one wonât?
Raw commented out code that somehow got itself into the commit conveys a mistake on the programmers behalf of forgetting to remove it after experimenting. I donât understand why would anyone interpret it any other way, and Iâve never seen anyone interpret it in any other way. It itâs in a comment - it has absolutely no hypothetical way to influence the program behavior in itâs state. A const
, at the very least for me, conveys some degree of configurability, which is not the thing I want for the dead code that I, or my coworker forgot to remove. Is it a const
set to false because it is configureable at compile time, or is it just a mark of the dead code? If there is a build flag related to it, does it mean that this is a toggleable feature, or something an author had to write because of apparent âbestâ practices?
How do you grep for commented out code btw?
The same way you grep a random const
youâve introduced as a workaround - you canât.
Or is it just ok for other people to spend effort in code review double-checking that you removed all of it.
Reviewing the code involves the reviewer reading the damn code. Youâre describing an issue that doesnât exist in the first place (and if it does - your workplace has way bigger problems than random comments amidst the code).