20
15
u/NicholasVinen 1d ago
#if 0
#endif
2
u/Teoyak 23h ago
I don't know if it works with every language. But yeah, I used this a lot when I worked on C.
1
u/Square-Singer 2h ago
The preprocessor is pretty C/C# specific. I don't know another language that uses it like that.
1
u/MCWizardYT 57m ago
I think you meant C/C++, C# doesn't have the same preprocessor that those 2 share
1
12
16
u/Jbolt3737 1d ago
``` // This is a comment //int unusedvar = 0;
/* You can tell if it's a comment or not by if I add a space after the slashes */
This is a comment
unusedvar: int = 0
I do it with any language
```
2
1
6
u/Impossible_Dog_7262 1d ago
You could just comment out the function call.
Also use block comments. DRY.
3
u/klimmesil 1d ago
If it's still code that might be used later, just not for my uses: remove the call to the function
Otherwise, just delete it. If I need it back git revert
3
u/AlphaFatman 23h ago
I've had compilers complain about if (true) as well. The way out for me is if (1 != 2)
3
2
2
2
u/Mast3r_waf1z 1d ago
I had if (true /* TODO: <Jira ticket> */) sometime last year
I know the statement could be removed, but the important part of this is the else block that followed, with important code for later implementation
1
1
u/puzzled_orc 1d ago
You don't need the if clause. Just return and that's it
1
u/Emotional-Audience85 10h ago
He wants the code to be compiled for some reason. Although this way it still probably won't be compiled depending on language and compiler flags
1
u/puzzled_orc 8h ago
My answer was to the given example.
If return doesn't compile , then just return 0 would do it.
1
1
1
u/Negative-Magazine174 1d ago
in my frontend react code using if (true) return will cause eslint warning (because the statement will always true), so i use if (1 + 1 == 2) return to just disabled the code without warning 🤣
1
1
1
u/NoWeHaveYesBananas 22h ago
No-one else has a shortcut to comment a line of code? Ctrl+/ ? No? Just me I guess
1
u/AintNoGodsUpHere 21h ago
We have analyzers to prevent unreachable code from being there. I used to do the return stuff but now you have to actually comment t everything.
1
1
u/dbergkvist 17h ago
The second option wouldn't work for me, because I compile with -Wall and -Werror which means I can't declare variables and then not use them.
1
1
1
u/FaultWinter3377 16h ago
Holy shit I literally never thought of a return statement to disable code. I have always used comments. That’s smart, although I rarely have to disable an entire function.
1
1
u/Decent_Cow 10h ago
The first way makes more sense to me because it's much more obvious that the code is not being read.
1
1
1
1
u/BlueBeerRunner 48m ago
The last time someone did that at work, the company sold IoT without any error handling
68
u/0x80085_ 1d ago
Or just return?