if(false) is an error?

It seems that in BaseLanguage, if (false) { ... } is an error because the body is an unreachable node. Is this intentional or a bug? It is incompatible with Java, so I would call it a bug.
BaseLanguage deliberately diverts from Java in several places. For example, the "return" keyword is not mandated in some cases, or braces are always required around IfStatement's body. For if (false) we decided to be less permissive than Java and report unreachable code as errors.
Two thoughts:

1. It is useful to have a way to suppress execution of code while continuing to validate the code e.g. for type errors. Does BaseLanguage have an equivalent? It looks like CommentedStatementBlock suppresses errors.

2. Perhaps the java importer should convert if (false) to a CommentedStatementBlock or equivalent?

1. To comment out a statement, hit Control/Cmd + /
2. Yes, this could be possible and makes a lot of sense.
Yes, but unless I’m mistaken, commenting a statement is different than surrounding it with if (false). The commented statement will not participate in refactoring or find usages. If the commented statement refers to X and the signature of X is changed, no warning will be given. If I did not want these things to happen, I would have commented out the code in the Java program.

I would still argue that if (false) is a useful programming tool and it is hard to believe that one would write if (false) by mistake, and isn’t the point of error messages to identify mistakes?
Since in MPS commented code is still a code (not a plain text), it does participate in refactorings and find usages.

Personally I don't think that using if(false), while(false) etc is a good practice so this case should be considered separately. It's good to comment what you want to comment. In Java you don't use this technique everywhere due to tooling problems you've mentioned. But if we are arguing about tooling, it's not a problem in MPS at all to make comments work as we want.

Moreover, (again just IMO) making baseLanguage behaviour as close to Java behaviour in such cases is just not worth it; just makes not-so-experienced-in-java user wonder, why if (1!=1){} is a mistake and if (false) is not.

However, "if(false)" transformation in importer is a good idea since it makes less readable code more readable, not vice versa ;)

Please sign in to leave a comment.