Skip to content

Conversation

@torusrxxx
Copy link
Contributor

This is a replacement for a previous pull request. Review suggestions have been addressed.
However, the code style and white-spaces review is so boring. Why didn't we have an automated tool that fixes it once and for all?

Juiceman and others added 7 commits March 17, 2024 21:25
Use Enhanced 'for' loops
Use Enhanced 'for' loops
# Conflicts:
#	src/freenet/clients/http/WelcomeToadlet.java
#	src/freenet/config/StringArrOption.java
#	src/freenet/support/PrioritizedSerialExecutor.java
@Bombe
Copy link
Contributor

Bombe commented Aug 22, 2025

However, the code style and white-spaces review is so boring. Why didn't we have an automated tool that fixes it once and for all?

Because we have 50+ open pull requests, and every single one of them would be fucked if we did that.

Copy link
Contributor

@Bombe Bombe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the variable names you introduced could be improved, too, e.g. the s in String s : methodNamesArray could incredibly well be named methodName to make it more clear what the variable does actually contain.

if (logMINOR) Logger.minor(this, "Updating bookmark for " + furi + " to edition " + edition);
matched = true;
BookmarkItem item = items.get(i);
BookmarkItem item = bookmarkItem;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, please don’t do this, use bookmarkItem instead of item in the line below. 🙂

Integer prev = results.get(result);
if(prev == null) prev = 0;
results.put(result, prev+1);
if (prev == null) prev = Integer.valueOf(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No manual boxing, please.

if (a[i] > max) max = a[i];
}
int max;
max = Integer.max(Arrays.stream(a).reduce(Integer::max).orElse(1), 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method does not need to be more than a single line. The declaration does not need to be separate, and the variable can be inlined directly.

PeerNodeStatus peerNodeStatus;
double peerLocation;
int histogramIndex;
int peerCount = peerNodeStatuses.length;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peerCount is now unused and can be removed.

for (int peerIndex = 0; peerIndex < peerCount; peerIndex++) {
peerNodeStatus = peerNodeStatuses[peerIndex];
for (PeerNodeStatus nodeStatus : peerNodeStatuses) {
peerNodeStatus = nodeStatus;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don’t introduce these kind of alias variables, please. Either use the name from the old loop in the for statement, or change all the variables in the loop to what you used in the new for statement.

Object[] sampleObjects = createSampleObjects(size);
for (int i=0;i<sampleObjects.length;i++)
methodLRUQueue.push(sampleObjects[i]);
for (Object sampleObject : sampleObjects) methodLRUQueue.push(sampleObject);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple lines and braces, please. For the remainder of this file, too.

private boolean isPresent(Object[] anArray, Object aElementToSearch) {
for(int i=0; i<anArray.length; i++)
if (anArray[i].equals(aElementToSearch))
for (Object o : anArray)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Braces, please.

methodSFS.putSingle(aPairsArray[i][0], aPairsArray[i][1]);
for (int i = 0; i < aPairsArray.length; i++) //getting values
retValue &= methodSFS.get(aPairsArray[i][0]).equals(aPairsArray[i][1]);
for (String[] value : aPairsArray) methodSFS.putSingle(value[0], value[1]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, this pull request started quite well in the “multiple lines and braces” area, but it seems to degrade more and more? I will not comment this on every of the remaining files where this occurs but will mention it here once for the remainder of this pull request: when you change code that either lumps up multiple statements in one line, or that uses multiple lines with identation, but without braces, change that code to be multiple lines (one line per statement) and to have braces around each code block.

}

@Test
public void testToMillis_fractionalMillis() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And where did this test go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automatic merging seems to mess up with this one and the next one.

try {
TimeUtil.toMillis("15250284452w3q7h12m55.807s");
} catch (NumberFormatException e) {
assertNotNull(e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm, no. a) This doesn’t even perform the check correctly, i.e. if toMillis does not throw, this test is still green. b) assertThrows is the perfect way to verify that a method throws an exception. c) The exception captured in a catch is always non-null, that assertNotNull is useless.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was probably written before assertThrows is supported. Many test cases in this test suite have been updated to use assertThrows.

@torusrxxx
Copy link
Contributor Author

However, the code style and white-spaces review is so boring. Why didn't we have an automated tool that fixes it once and for all?

Because we have 50+ open pull requests, and every single one of them would be fucked if we did that.

30+ open pull requests are older than 2 years, and every single one of them already needs complete rework to get merged.

blubskye added a commit to blubskye/fred that referenced this pull request Dec 4, 2025
Address code review feedback from PR hyphanet#1100:
- Replace single-letter variables with descriptive names:
  - s -> metaString, headerValue, nodeReference, octet, nodeName
  - r -> requestStatus
  - f -> file
  - a/b -> nodeA/nodeB
- Replace generic 'item' with specific 'bookmarkItem'

Based on PR hyphanet#1100 by Juiceman and torusrxxx

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Juiceman <juiceman@hyphanet.org>
Co-Authored-By: torusrxxx <torusrxxx@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants