Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharing iP code quality feedback [for @bryanljx] - Round 2 #4

Open
nus-se-bot opened this issue Oct 11, 2022 · 0 comments
Open

Sharing iP code quality feedback [for @bryanljx] - Round 2 #4

nus-se-bot opened this issue Oct 11, 2022 · 0 comments

Comments

@nus-se-bot
Copy link

@bryanljx We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, so that you can avoid similar problems in your tP code (which will be graded more strictly for code quality).

IMPORTANT: Note that the script looked for just a few easy-to-detect problems only, and at-most three example are given i.e., there can be other areas/places to improve.

Aspect: Tab Usage

No easy-to-detect issues 👍

Aspect: Naming boolean variables/methods

No easy-to-detect issues 👍

Aspect: Brace Style

No easy-to-detect issues 👍

Aspect: Package Name Style

No easy-to-detect issues 👍

Aspect: Class Name Style

No easy-to-detect issues 👍

Aspect: Dead Code

No easy-to-detect issues 👍

Aspect: Method Length

Example from src/main/java/gui/DukeGui.java lines 39-92:

    public void start(Stage stage) {
        scrollPane = new ScrollPane();
        dialogContainer = new VBox();
        scrollPane.setContent(dialogContainer);

        displayIntroMessage();

        userInput = new TextField();
        sendButton = new Button("Send");

        AnchorPane mainLayout = new AnchorPane();
        mainLayout.getChildren().addAll(scrollPane, userInput, sendButton);

        scene = new Scene(mainLayout);

        stage.setScene(scene);
        stage.show();

        stage.setTitle("Duke");
        stage.setResizable(false);
        stage.setMinHeight(600.0);
        stage.setMinWidth(400.0);

        mainLayout.setPrefSize(400.0, 600.0);

        scrollPane.setPrefSize(385, 535);
        scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
        scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);

        scrollPane.setVvalue(1.0);
        scrollPane.setFitToWidth(true);

        dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE);

        userInput.setPrefWidth(325.0);

        sendButton.setPrefWidth(55.0);

        AnchorPane.setTopAnchor(scrollPane, 1.0);

        AnchorPane.setBottomAnchor(sendButton, 1.0);
        AnchorPane.setRightAnchor(sendButton, 1.0);

        AnchorPane.setLeftAnchor(userInput , 1.0);
        AnchorPane.setBottomAnchor(userInput, 1.0);

        sendButton.setOnMouseClicked((event) -> {
            handleUserInput();
        });

        userInput.setOnAction((event) -> {
            handleUserInput();
        });
    }

Example from src/main/java/util/Parser.java lines 35-88:

    public static Command parseInputLine(String inputLine) throws DukeException {
        String[] splitted = inputLine.split("\\s+", 2);
        String command = splitted[0];
        Command cmd;
        switch (command) {
        case "bye":
            cmd = new TerminateCommand();
            break;
        case "list":
            cmd = new ListAllTasksCommand();
            break;
        case "mark":
            int index = Integer.parseInt(splitted[1]);
            cmd = new MarkTaskCommand(index);
            break;
        case "unmark":
            index = Integer.parseInt(splitted[1]);
            cmd = new UnmarkTaskCommand(index);
            break;
        case "delete":
            index = Integer.parseInt(splitted[1]);
            cmd = new DeleteTaskCommand(index);
            break;
        case "todo":
            Todo.validateInput(splitted);
            assert splitted.length >= 2 : "No of arguments should be more than 1.";
            Task todo = new Todo(splitted[1]);
            cmd = new AddTaskCommand(todo);
            break;
        case "deadline":
            // Regex "\\s+/" matches one or more space followed by a /by,
            // followed by one or more space
            String[] taskArgs = splitted[1].split("\\s+/by\\s+", 2);
            DeadlineDateTime deadlineDateTime = DeadlineDateTime.parseDate(taskArgs[1]);
            Task deadline = new Deadline(taskArgs[0], deadlineDateTime);
            cmd = new AddTaskCommand(deadline);
            break;
        case "event":
            // Regex "\s+/at\s+" matches one or more space followed by a /at,
            // followed by one or more space
            taskArgs = splitted[1].split("\\s+/at\\s+", 2);
            EventDateTime eventDateTime = EventDateTime.parseDate(taskArgs[1]);
            Task event = new Event(taskArgs[0], eventDateTime);
            cmd = new AddTaskCommand(event);
            break;
        case "find":
            String searchText = splitted[1];
            cmd = new FindSearchTextCommand(searchText);
            break;
        default:
            throw new DukeException(DukeException.ErrorCode.UNKNOWN_CMD);
        }
        return cmd;
    }

Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods e.g., extract some code blocks into separate methods. You may ignore this suggestion if you think a longer method is justified in a particular case.

Aspect: Class size

No easy-to-detect issues 👍

Aspect: Header Comments

Example from src/main/java/task/Deadline.java lines 13-17:

    /**
     * {@inheritDoc}
     *
     * @param deadline Deadline of the task
     */

Example from src/main/java/task/Event.java lines 13-17:

    /**
     * {@inheritDoc}
     *
     * @param eventTiming Date and time of the event
     */

Example from src/main/java/task/Todo.java lines 11-13:

    /**
     * {@inheritDoc}
     */

Suggestion: Ensure method/class header comments follow the format specified in the coding standard, in particular, the phrasing of the overview statement.

Aspect: Recent Git Commit Message (Subject Only)

No easy-to-detect issues 👍

Aspect: Binary files in repo

No easy-to-detect issues 👍

❗ You are not required to (but you are welcome to) fix the above problems in your iP, unless you have been separately asked to resubmit the iP due to code quality issues.

ℹ️ The bot account used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact cs2103@comp.nus.edu.sg if you want to follow up on this post.

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

No branches or pull requests

1 participant