Code Review – CMP1903M Resit Assessment#8
Open
jesse1234-cyber wants to merge 2 commits 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
Variable names like
z,q,a,s, andtare not meaningful.Suggest renaming:
z→ File Pathq→ linesa→ wordcountss→ cleaned Linet→ wordsCode Structure
Entire logic is written inside the main() method.
This breaks modularity and reusability.
Suggest creating separate methods:
Read File()Process Words()Display Results()`Error Handling
No handling for invalid file paths or read errors.
Program crashes if file is missing.
Suggesting that wrapping
File.ReadAllLines(z)in a try-catch block to show a user-friendly error message.File Assumptions
No validation or checks for empty lines or invalid content.
Suggest checking if file exists and has content before processing.
OOP Principles
The program is purely procedural.
No use of classes or encapsulation.
suggested that introducing a
Word ProcessororWord Counterclass with clear responsibilities Single Responsibility Principle.Output
The output is functional but basic.
Suggest:
Sorting the dictionary alphabetically or by frequency
Formatting output using
Console. WriteLine($"{word}: {count}")Program Logic
Logic is correct: reads lines, cleans words, counts, and displays results.
Regex and dictionary usage is appropriate.
Could be optimized slightly by trimming whitespace and removing unnecessary checks.