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 @Statspadders] #3

Open
soc-se-script opened this issue Feb 11, 2023 · 0 comments
Open

Sharing iP code quality feedback [for @Statspadders] #3

soc-se-script opened this issue Feb 11, 2023 · 0 comments

Comments

@soc-se-script
Copy link

@Statspadders We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, to help you improve the iP code further.

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

Example from src/main/java/duke/command/ExitCommand.java lines 12-12:

    boolean exit;

Example from src/main/java/duke/task/Task.java lines 8-8:

    private boolean mark;

Suggestion: Follow the given naming convention for boolean variables/methods (e.g., use a boolean-sounding prefix).You may ignore the above if you think the name already follows the convention (the script can report false positives in some cases)

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

Example from src/main/java/duke/Parser.java lines 173-173:

    //try and catch for tk.nextToken() for integer;

Suggestion: Remove dead code from the codebase.

Aspect: Method Length

Example from src/main/java/duke/Parser.java lines 50-171:

    public Command parse(String fullCommand, Ui ui) {
        this.fullCommand = fullCommand;
        this.tk = new StringTokenizer(fullCommand);
        this.ui = ui;

        String action = nextString();
        Command c = null;
        Task t;

        switch (action) {
        case "list":
            c = new ListCommand();
            break;
        case "mark": {
            int index = getIndex();
            c = new MarkCommand(index);
            break;
        }
        case "delete": {
            int index = getIndex();
            c = new DeleteCommand(index);
            break;
        }
        case "find": {
            String value = nextString();
            if (value != null) {
                c = new FindCommand(value);
            }
            break;
        }
        case "todo": {
            String value = getToDo();
            if (value != null && !value.isEmpty())  {
                t = new Todo(value, false);
                c = new AddCommand(t);
            } else {
                c = new ErrorCommand(ErrorCommand.types.emptyDesc,"todo");
            }
            break;
        }
        case "deadline": {
            String input;
            String value = "";
            String date ;
            boolean isBy = false; // Check whether the user has typed /by in his command

            while ((input = nextString()) != null) {
                if (input.equals("/by")) {
                    date = nextString();
                    isBy = true;
                    LocalDateTime dateTime = stringToDateTime(date);
                    if(dateTime != null) {
                        t = new Deadline(value, dateTime, false);
                        c = new AddCommand(t);
                    } else {
                        c = new ErrorCommand(ErrorCommand.types.dateTime,"deadline");
                    }
                    break;
                } else
                    value = value + input;
            }

            if(value == "") {
                c = new ErrorCommand(ErrorCommand.types.emptyDesc,"deadline");
            } else if (isBy == false) {
                c = new ErrorCommand(ErrorCommand.types.missingBy,"deadline");
            }
            break;
        }
        case "event": {
            String input;
            String value = "";
            String from;
            String to ;
            boolean isFrom = false;

            while ((input = nextString()) != null) {
                if (input.equals("/from")) {
                    from = nextString();
                    LocalDateTime dateTime;
                    isFrom = true;
                    dateTime = stringToDateTime(from);
                    if(dateTime == null) {
                        c = new ErrorCommand(ErrorCommand.types.dateTime,"event from");
                        break;
                    }
                    String isTo = nextString();
                    if(!(isTo != null && isTo.equals("/to"))) {
                        c = new ErrorCommand(ErrorCommand.types.missingTo,"event to");
                        break;
                    }
                    to = nextString();
                    LocalDateTime dateTime2;
                    dateTime2 = stringToDateTime(to);
                    if(dateTime2 == null) {
                        c = new ErrorCommand(ErrorCommand.types.dateTime,"event to");
                        break;
                    }
                    t = new Event(value, dateTime, dateTime2, false);
                    c = new AddCommand(t);
                    break;
                } else
                    value = value + input;
            }

            if(value == "") {
                c = new ErrorCommand(ErrorCommand.types.emptyDesc,"event");
            } else if (isFrom == false) {
                c = new ErrorCommand(ErrorCommand.types.missingFrom,"event");
            }
            break;
        }
        default:
            c = new UnknownCommand();
            break;
        }

        //Assertion Check
        assert c == null: "Command c should not be null";

        return c;
    }

Example from src/main/java/duke/gui/Start.java lines 54-126:

    public void start(Stage stage) throws Exception {

        //Step 0. Setting up the instances
        initalize("data/duke.txt");

        //Step 1. Setting up required components

        //The container for the content of the chat to scroll.
        scrollPane = new ScrollPane();
        dialogContainer = new VBox();
        scrollPane.setContent(dialogContainer);

        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();

        //Step 2. Formatting the window to look as expected
        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);

        // You will need to import `javafx.scene.layout.Region` for this.
        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);

        //Step 3. Add functionality to handle user input.
        sendButton.setOnMouseClicked((event) -> {
            handleUserInput();
        });

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

        //Scroll down to the end every time dialogContainer's height changes.
        dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0));

        //Step 4. Welcome Message
        dialogContainer.getChildren().addAll(
                DialogBox.getDukeDialog(getDialogLabel(ui.welcomeMessage()), new ImageView(duke))
        );



    }

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/duke/Storage.java lines 27-32:

    /**
     * Read tasks from file, and add them all into a list.
     *
     * @return ArrayList<Task> that contains all the tasks
     * @throws IOException
     */

Example from src/main/java/duke/Storage.java lines 64-67:

    /**
     * Write a new line to the file
     * @param t = task
     */

Example from src/main/java/duke/Storage.java lines 78-80:

    /**
     * Remove all text from the file
     */

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 👍

ℹ️ 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