congo-cc / congo-parser-generator

The CongoCC Parser Generator, the Next Generation of JavaCC 21, which in turn was the next generation of JavaCC
https://discuss.congocc.org/
Other
36 stars 11 forks source link

Do not declare more than one variable per declaration #21

Closed stbischof closed 1 year ago

stbischof commented 1 year ago

Where:

https://github.com/congo-cc/congo-parser-generator/blob/main/src/templates/java/Lexer.java.ftl#L183 https://github.com/congo-cc/congo-parser-generator/blob/main/src/templates/java/Lexer.java.ftl#L185-186

Why: CERT, DCL52-J. - Do not declare more than one variable per declaration CERT, DCL04-C. - Do not declare more than one variable per declaration

revusky commented 1 year ago

Okay, so the claim being made here is that the following code is bad:

 int start = position, matchLength = 0;

It should be written in two lines:

 int start = position;
 int matchLength = 0;

Well, unlike the previous claim, that static private should be rewritten as private static, which I am satisfied is nonsense, this one I'm less certain about. It could well be that it's a bit better to write it as two lines. On the whole, though, it looks pretty marginal to me. Especially in this specific case, where the code is in a template, and thus, the code is generated. I mean, in general, people rarely have any reason to eyeball the generated files anyway. (Though, sometimes one does...)

By the way, of the two documents cited above, the second one is for C programming really, and the case is stronger in C, because uninitialized variables really can be an issue. In Java, the system protects you from accessing an uninitialized variable anyway.

Well, finally, I think my preferred "solution" to this "problem" is the same as it is for the "static private" "problem". I think you should turn off the warning. I appreciate your interest and your dilligence though.

stbischof commented 1 year ago

You are right, it is `pretty marginal. But Code-Checkers will warn you here. And its really easy to change.

I could do this PR. if this would be accaprable.