Skip to content

Create Code review (resit)#9

Open
Sam-H06 wants to merge 1 commit into
cfrantzidis:masterfrom
Sam-H06:patch-1
Open

Create Code review (resit)#9
Sam-H06 wants to merge 1 commit into
cfrantzidis:masterfrom
Sam-H06:patch-1

Conversation

@Sam-H06

@Sam-H06 Sam-H06 commented Jul 28, 2025

Copy link
Copy Markdown

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 main method. 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

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.

1 participant