Skip to content

Sharing iP code quality feedback [for @flyingsalsa] - Round 2 #6

@nus-se-bot

Description

@nus-se-bot

@flyingsalsa 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/notgpt/ui/NotgptJavaFX.java lines 74-139:

    public void start(Stage primaryStage) {


        // Set Application icon
        primaryStage.setTitle("Notgpt");
        Image icon = new Image(getClass().getResourceAsStream("/icon.png"));
        primaryStage.getIcons().add(icon);

        // Load avatar images
        userAvatar = new Image(getClass().getResourceAsStream("/user_avatar.png"));
        botAvatar = new Image(getClass().getResourceAsStream("/bot_avatar.jpg"));
        assert userAvatar != null : "there is no user image";
        assert botAvatar != null : "there is no bot image";

        Circle clip = new Circle(45);

        // Create UI components
        chatBox = new VBox(10);
        chatBox.setPadding(new Insets(10));
        chatBox.setStyle("-fx-background-color: #ECE5DD;");

        scrollPane = new ScrollPane(chatBox);
        scrollPane.setFitToWidth(true);
        scrollPane.setFitToHeight(true);
        scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);

        inputField = new TextField();
        inputField.setPromptText("Type a message");
        inputField.setPrefHeight(80);
        inputField.setFont(Font.font("System", FontWeight.NORMAL, FONT_SIZE_INPUT));

        sendButton = new Button("Send");
        sendButton.setPrefHeight(40);
        sendButton.setStyle("-fx-background-color: #128C7E; -fx-text-fill: white;");

        HBox inputBox = new HBox(10);
        inputBox.setAlignment(Pos.CENTER);
        inputBox.setPadding(new Insets(10));
        inputBox.setStyle("-fx-background-color: #F0F0F0;");
        HBox.setHgrow(inputField, Priority.ALWAYS);
        inputBox.getChildren().addAll(inputField, sendButton);

        // Layout
        VBox vBoxRoot = new VBox();
        VBox.setVgrow(scrollPane, Priority.ALWAYS);
        vBoxRoot.getChildren().addAll(scrollPane, inputBox);

        // Set up the scene
        Scene scene = new Scene(vBoxRoot, 500, 800);
        primaryStage.setScene(scene);
        scene.getStylesheets().add("css/ScrollbarStyle.css");

        // Event handling
        sendButton.setOnAction(e -> sendMessage());
        inputField.setOnAction(e -> sendMessage());

        String logo = "_   _       _                       _\n"
                + "| \\ | |  _  | |_        __  __    | |__\n"
                + "|  \\| |/ _ \\  __|    / _` | '_ \\ |  __|\n"
                + "| |\\  | (_) | |_     | (_|  | |_)  |  |_\n"
                + "|_| \\_|\\__/ \\__|   \\__, | __/  \\__|\n"
                + "                       |___/|_|\n";
        // Initial message
        displayMessage(logo + "\n" + "hi, I'm Not-gpt,\ndo you really need me to do sth for you?", false);
        primaryStage.show();
    }

Example from src/main/java/notgpt/ui/NotgptJavaFX.java lines 161-223:

    private void displayMessage(String message, boolean isUser) {
        Text messageText = new Text(message);
        messageText.setFont(Font.font("System", FontWeight.NORMAL, FONT_SIZE));

        // Create TextFlow
        TextFlow textFlow = new TextFlow(messageText);
        textFlow.setPadding(new Insets(8));
        textFlow.setMaxWidth(220);
        double maxHeight = 40;
        textFlow.setMaxHeight(maxHeight);

        // Calculate preferred height
        double prefHeight = messageText.getLayoutBounds().getHeight() + 16; // Padding
        textFlow.setPrefHeight(Math.min(prefHeight, maxHeight));

        // Create avatar
        ImageView avatarView = new ImageView(isUser ? userAvatar : botAvatar);
        avatarView.setFitHeight(90);
        avatarView.setFitWidth(90);
        VBox avatarWrapper = new VBox();
        avatarWrapper.setMaxHeight(90);
        avatarWrapper.setMaxWidth(90);
        avatarWrapper.getChildren().add(avatarView);
        avatarWrapper.setPadding(new Insets(0, 0, 4, 0)); // Add bottom padding here

        Circle clip = new Circle(45, 45, 45);
        avatarView.setClip(clip);

        // Create Circle for avatar border
        Circle borderCircle = new Circle(45, 45, 45);
        borderCircle.setStroke(Color.WHITE);
        borderCircle.setStrokeWidth(8);
        borderCircle.setFill(Color.TRANSPARENT);

        // Create StackPane for avatar and border
        StackPane avatarContainer = new StackPane();
        avatarContainer.getChildren().addAll(borderCircle, avatarWrapper);
        avatarContainer.setAlignment(Pos.CENTER); // Align avatar to bottom

        StackPane avatar = new StackPane();
        avatar.getChildren().add(avatarContainer);
        avatarContainer.setAlignment(Pos.BOTTOM_CENTER);

        // Create HBox for message and avatar
        HBox messageBox = new HBox(10);
        messageBox.setAlignment(isUser ? Pos.BOTTOM_RIGHT : Pos.BOTTOM_LEFT);
        messageBox.setPrefHeight(Region.USE_COMPUTED_SIZE);

        // Add message text and avatar to HBox
        if (isUser) {
            textFlow.setStyle("-fx-background-color: #DCF8C6; -fx-background-radius: 12 12 0 12;");
            messageBox.getChildren().addAll(textFlow, avatar);
        } else {
            textFlow.setStyle("-fx-background-color: white; -fx-background-radius: 12 12 12 0;");
            messageBox.getChildren().addAll(avatar, textFlow);
        }
        chatBox.getChildren().add(messageBox);

        Platform.runLater(() -> {
            scrollPane.layout(); // Force scrollPane to refresh layout
            scrollPane.setVvalue(1.0); // Scroll to the bottom
        });
    }

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

No easy-to-detect issues 👍

Aspect: Recent Git Commit Message

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions