Create Code review (resit)#9
Open
Sam-H06 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Naming:
names of variables lack description and are not-meaningful which make the code hard to read/understand and maintain. Here are some suggested changes that could improve readability.
"z" = filePath
"q" = fileLines
"a" = wordFrequencies
"s" = cleanedLine
"t" = wordsInLine
"w" = word
"e" = entry
Code Structure:
Everything is happening in
mainmethod. This makes the code hard to test, reuse, and maintain. Suggested fixes could be to separate Logic into methods and/or classes such as: method for reading and cleaning text, method for counting words, and method for displaying results.Error Handling:
Does not check if file exists, code crashes the program. Even if file exists, other exceptions can occur.
Could use file.exists() to check before you try to read the file, acting as a safety gate.
File assumptions:
Code assumptions file exists and can be read, also assumes file is not empty.
a suggestion would be checking if file exists and making sure content inside is valid.
OOP principles:
No use of encapsulation - as all logic is in main()
input, processing and output are all tangled together, suggest using classes to separate each concern.
Output:
all output logic is hardcoded into main() - no way to reuse or customise output, makes program harder to extend or test.
suggest create a dedicated class for displaying or extending results.
Program Logic:
There's no handling of empty or invalid words.
-if a line is empty or contains only punctuation, splitting could produce empty strings.
-empty strings might still be processed unnecessarily