Effective low-tech alternative to @formatter:off for Java
I love automatic formatting for source code. Back in 2004 I scrapped the detailed formatting guide for the project I was running and replaced it with a single sentence: all code must be formatted by the automatic formatter using the project’s conventions. Done. Sure, manual formatting can look better, but at what cost (and tedium)?
There are some places where the automatic formatter always fails, though, for example string concatenation for SQL commands. No problem, use @formatter:off and @formatter:on and there you are – until someone comes along who hasn’t enabled the tags. And disabling formatting completely can introduce tabs where there should be spaces, for example.
Fortunately there is an effective low-tech alternative that works everywhere (cross-IDE): comments! Use line comments after each line and the formatter can’t join them:
"select something from some_table " // + " where some_column = ?"
It will still handle indentation.