Code review for CMP1903M Resit Assessment#6
Open
jesse1234-cyber 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
Strength: Code has some recognizable variable names like wordcounts and file Path.
Issues:
Variable names like s, t, and w are vague and not self-explanatory.
Suggestions:
Rename variables for better readability:
s → cleaned Line
t → words
w → word
lines → file Lines
Code Structure
Strength: Code logic is clear and performs as expected.
Issues:
Entire logic is inside the Main() method, which reduces modularity.
Suggestions:
Break the program into reusable methods like:
Read File(string file Path)
Process Lines(string[] lines)
Display Wordcounts(Dictionary<string, int> wordcounts)
Error Handling
Strength: Basic file existence check using File.Exists().
Issues:
No exception handling for ReadiLine() or unexpected errors.
Suggestions:
Add messages to guide the user if the file path is invalid or empty.
File Assumptions
Issues:
Assumes file exists and has valid content.
Doesn’t check if lines are empty or if file is unreadable.
Suggestions:
Add user feedback for such conditions.
OOP Principles
Issues:
Entire logic is in a single class with one method.
Lacks encapsulation and separation of concerns.
Suggestions:
Apply basic OOP structure:
class FileProcessor { string[] ReadFile(); }
class WordAnalyzer { Dictionary<string,int> CountWords(); }
class DisplayHelper { void ShowResults(); }
This helps maintain, test, and extend the program.
Output
Strength: Output uses Console.WriteLine() for user interaction.
Issues:
Not formatted or sorted, making results harder to read.
Suggestions:
Display results alphabetically or by frequency.
Use clear headings like: --- Word Frequency Results ---.
Program Logic
Strength: Functional and loops through lines correctly.
Issues:
Logic for punctuation removal and splitting is correct but could use comments.
Suggestions:
Add comments above critical logic blocks.