Skip to content

[OTHER] Current code style does not look like java code #4204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
oppahansi opened this issue May 28, 2023 · 4 comments
Closed

[OTHER] Current code style does not look like java code #4204

oppahansi opened this issue May 28, 2023 · 4 comments
Labels

Comments

@oppahansi
Copy link

oppahansi commented May 28, 2023

What would you like to share?

Hi,

I stumbled on this repository earlier and was exploring its algorithm collection.
But I was really confused at the beginning. Almost all of the code does not look
like Java code.

You introduced this code style with this merge request.
I was wondering which reasons you had for this?

Cheers

Additional information

I would be willing to refactor the code using one of the common code styles, like google code style.

@oppahansi oppahansi added the awaiting triage Awaiting triage from a maintainer label May 28, 2023
@siriak
Copy link
Member

siriak commented May 28, 2023

Could you explain what specifically doesn't look like standard Java? The PR made a lot of changes, most of which are correcting missing whitespace and enforcing max line length

@siriak siriak added question and removed awaiting triage Awaiting triage from a maintainer labels May 28, 2023
@oppahansi
Copy link
Author

I might be a bit biased in this regard due to my preferences.
Here are some examples I have in mind:

Examples code style

KnightsTour.java

if (
	!orphanDetected(count, row, column) &&
	solve(row, column, count + 1)
) {
	return true;
}

AES.java

public static BigInteger addRoundKey(
	BigInteger ciphertext,
	BigInteger key
) {
	return ciphertext.xor(key);
}

AffineCipher.java

 if (cipher.charAt(i) != ' ') {
                msg =
                    msg +
                    (char) (
                        ((a_inv * ((cipher.charAt(i) + 'A' - b)) % 26)) + 'A'
                    );

Fibonacci.java

for (
	int intermediateIndex = 0;
	intermediateIndex < columnsInMatrix1;
	intermediateIndex++
) {
	matrixEntry +=
		matrix1[rowIndex][intermediateIndex] *
		matrix2[intermediateIndex][colIndex];
}

...

int[][] matrixExpResult = matrixMultiplication(
	cachedResult,
	cachedResult
);

... 

return matrixMultiplication(
	Fibonacci.fibMatrix,
	matrixExpResult
);

Vigenere.java

result.append(
	(char) (
		(c + key.toUpperCase().charAt(j) - 2 * 'A') %
		26 +
		'A'
	)
);

AnyBaseToAnyBase.java

System.out.print(
	"Enter beginning base (between " +
	MINIMUM_BASE +
	" and " +
	MAXIMUM_BASE +
	"): "
);

Others:

Examples others

Missing whitespaces in for loops
Missing whitespaces in for loops
Missing whitespaces between
Missing whitespaces between ){
C style code blocks
C style code blocks
One of many wrongly placed Javadoc comments
One of many wrongly placed Javadoc comments

Apart from these examples, there are also other unconventional "issues":

  • order of methods, fields, imports in classes
  • no concise use of javadoc / comments through many classes
  • variable naming conventions often ignored
  • class naming convention sometimes ignored
  • urls in javadoc comments not using the html tags
  • etc

All of these issues add up at the end. At least to me. (I am working with java code on a daily basis.)
Does this make sense?

@siriak
Copy link
Member

siriak commented May 28, 2023

I see your point. Unfortunately, we don't have automatic formatting checks like we have in Go repository, that's why it may not be consistent. The PR in question has fixed a lot of issues (empty lines, too long lines, and others), but has also introduced some new that you are pointing out.
Is there a tool that we can run in our CI pipeline to check formatting? If so, could you add it and format the code with it? That'd be ideal.

@oppahansi
Copy link
Author

AFAIK there are few, I will take a closer look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants