Reputation: 1088
I've received some code from someone who apparently likes to use the following syntax:
if(FALSE) {
opt <- list("cores" = 1, "degradation" = TRUE, "test" = TRUE)
}
What does this mean? If what is FALSE
? The last condition evaluated? I'm confused
Upvotes: 5
Views: 1032
Reputation: 41240
This one of the available techniques to comment out multiple lines of code.
advantages :
if (T)
instead of if (F)
disadvantage :
Upvotes: 4
Reputation: 545865
If what is
FALSE
?
FALSE
itself. FALSE
is a logical value. And the syntax for if
is
if (condition) …
That “condition” can be any expression that evaluates to something that R can interpret as a logical value. FALSE
is such an expression. So if (FALSE)
is basically the same as writing if (a condition that’s never true)
.
So this construct is quite meaningless: the whole if
block will always be skipped, you might as well remove it. As explained in the other answer, some people use this construct to easily disable larger chunks of code. I don’t recommend this practice: code that’s never evaluated is called dead code, and it’s clutter and thus incurs technical debt (all these are effectively terms that say that it decreases the overall code quality).
Upvotes: 3