Refactor methods for separation of concern#973
Refactor methods for separation of concern#973anonstudy wants to merge 1 commit intohyphanet:nextfrom
Conversation
There was a problem hiding this comment.
No. Please do not commit configuration for your local IDE.
| return false; | ||
| } | ||
| Logger.normal(this, "extraPeerDataFile: "+extraPeerDataFile.getPath()); | ||
| FileInputStream fis; |
There was a problem hiding this comment.
What is this? Unused, that’s what it is!
| Logger.normal(this, "extraPeerDataFile: "+extraPeerDataFile.getPath()); | ||
| FileInputStream fis; | ||
| SimpleFieldSet fs = readFile(extraPeerDataFile); | ||
| if (fs == null) return false; |
There was a problem hiding this comment.
Please add braces for all blocks.
| FileInputStream fis; | ||
| SimpleFieldSet fs = readFile(extraPeerDataFile); | ||
| if (fs == null) return false; | ||
| if(fs == null) { |
There was a problem hiding this comment.
Inconsistent whitespace (cf. to the line directly above this).
There was a problem hiding this comment.
Also, wait, what? fs has already been found to be non-null so this if can never be true.
| deleteExtraPeerDataFile(fileNumber); | ||
| return true; | ||
| } | ||
| boolean parseResult = false; |
There was a problem hiding this comment.
As this variable is not used outside the try block, please declare it inside the try block.
| Logger.error(this, "Could not parse extra peer data: "+e2+ '\n' +fs.toString(),e2); | ||
| gotError = true; | ||
| } | ||
| return !gotError; |
There was a problem hiding this comment.
This whole construct seems to be over-complicated. Both parseResult and gotError (declared at the wrong end of the method) do not fulfill any real purpose here and can be removed without any damage.
There was a problem hiding this comment.
Why are the changes for both of these files mixed into a single pull request? Please file separate pull requests; smaller pull requests are easier to handle than larger ones.
| return false; | ||
| } | ||
|
|
||
| private boolean shutdownAnnouncement() { |
There was a problem hiding this comment.
“shutdownAnnouncement” sounds like a command but the method doesn’t do anything, and it returns a value. What is actually meant here? Is the shutdown announcement being shown? Should it be? Should announcements be shut down? Please rename the method in a way that makes it clearer what it does.
| } | ||
| return true; | ||
| } | ||
| if (shutdownAnnouncement()) return true; |
There was a problem hiding this comment.
Always use braces for blocks, and only one statement per line, please.
Sorry for barging into this, apparently I had started a review a couple of weeks ago but never got around to finish it. :) |
I reviewed just the change — the refactoring — not the original code. There are a lot more issues in the original code than just the ones fixed here, but I think they can be fixed in an independent PR. |
Some of the code is indeed the original code, just moved around, but some of it is new code, and for that code my comments still stand. 🙂 |
|
@anonstudy are you planning to still do changes for the review by @Bombe ? |
Changes proposed in this pull request:
Announcer.Java
This PR refactors the enoughPeers method by extracting the logic for shutting down the announcement into a separate method.
Changes:
shutdownAnnouncementin the classenoughPeersmethod to callshutdownAnnouncementwhere appropriateRationale:
Note:
DarknetPeerNode.Java
This PR refactors the readExtraPeerDataFile method by extracting the file reading logic into a separate method.
Changes:
readFilethat takes a file path as input and returns the file contents as a stringRationale:
Note: