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

Refactoring: Enhancing code maintainability by reducing code smells. #1336

Open
wants to merge 32 commits into
base: dev
Choose a base branch
from

Conversation

Yukta026
Copy link

@Yukta026 Yukta026 commented Mar 23, 2024

By this pull request, I am reaching out to submit my refactoring improvements for your consideration.
These changes aim to improve readability, maintainability, and performance while aligning with best practices and the project's objectives.

aNNiMON and others added 20 commits January 22, 2024 20:10
A semicolon were missing in the Standalone reply code.
The reply signature changed and needs a BiConsumer<BaseAbilityBot, Update> instead of Consumer<Update> in the Ability reply
…ed from 'Boolean' to 'String' (according to TelegramBotAPI Official Documentation). (rubenlagus#1315)
* fix force=true for WriteAccessAllowed

* + test and fixtures on write access allowed
* Fix path for GetMyName method

* Add missing sticker methods from API 6.6

* Fix possible NPE in InputSticker validation

* Add ReplyParameters to SendInvoice API method

* Removed mysterious fields in SetChatTitle
…ing renaming method and introducing explaining variable technique
…larization using change bidirectional association to unidirectional association

technique
@Chase22
Copy link
Collaborator

Chase22 commented Mar 25, 2024

Something is not right with the git commits in this PR. It's trying to merge a lot more commits than it should. Please make sure you branch is up to date and based on the devbranch.

I'll be looking through these but please tell your professor that open-source developers aren't outsourced teachers and that we have to invest quite significant time into the reviews.

@Yukta026 Yukta026 changed the title Refactoring: Enhancing code maintainability by reducing implementation and design smells(as part of Course Assignment). Refactoring: Enhancing code maintainability by reducing code smells. Mar 26, 2024
@Yukta026
Copy link
Author

Thank you for taking the time to review my pull request and providing feedback. To address the issue regarding the git commits, I've conducted a thorough analysis of the changes made. In total, there are 11 commits originating from my assignment2 branch, affecting a total of 21 files.

Furthermore, I've ensured that my branch is up to date and based on the dev branch by incorporating the latest changes from the dev branch into my own. This includes resolving any merge conflicts that arose, such as the one encountered in the Story.java file.

I greatly appreciate the time and effort you've dedicated to reviewing my contributions to this repository. My ultimate goal is to make meaningful contributions, and I'm committed to ensuring the quality and integrity of my work. Please feel free to take as much time as needed for further review.

Copy link

@Senderman Senderman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to help the developer of this library so I did my own code review. See the github code comments.
Also, why do you leave explanations to your refactor in the code comments? Keep in mind that you request to merge your code (including comments) into the upstream repository. Which means people who would like to inspect the code in the future and create their own pull requests, will have to read through your changelog in the code, when there's VCS (git) for this

final String METHOD_NAME_CONSTRAINT = "cannot be longer than 31 characters, and cannot be null";

// isValueCommandName renamed to isValCmdName
checkArgument(isValCmdName(name), INVALID_METHOD_NAME_ERROR+METHOD_NAME_CONSTRAINT, name);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in java, it's inconvenient to use abbreviations like here. use isValidCommandName

@@ -22,6 +22,9 @@ public class MessageContext {
private final Update update;
private final BaseAbilityBot bot;

// Refactored code-Added thirdArg as explaining variable to remove magic number 2
int thirdArg = 2;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when did array index become a magic number?

/*
* Refactored code - Insufficient Modularization design smell refactored by moving the methods related to send functionality
* and extracting class DefaultSender1.
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes more "code smell" by creating non-obvious DefaultSender1 class (how end-users should understand the difference?) why methods related to sending are moved from DefaultSender class?

@@ -0,0 +1,39 @@
package org.telegram.abilitybots.api.sender;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comments about DefaultSender1

public static boolean isValidCommandName(String commandName){

// Refactored code by renaming isValueCommandName to isValCmdName method
public static boolean isValCmdName(String commandName){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in java, it's inconvenient to use abbreviations like here. No need for renaming

}

@Test
public void testcommandIdentifierStartsWithCOMMAND_INIT_CHARACTER()
Copy link

@Senderman Senderman Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only String objects and its methods are involved in this test. What are you trying to test here is core java's String.substring method, but it's not related to the library code, because this library doesn't hack into JVM

};

// Act
Long chatId = 002L;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not to use 2L or just 2?

@Override
public String getMethod() {
return PATH;
}

@Override
public void validate() throws TelegramApiValidationException {
// Old code - validate() method was containing complex method and complex conditional code smells

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you store old code in comments when using VCS (git)?

@@ -30,7 +30,8 @@
@AllArgsConstructor
public class Chat implements BotApiObject {

private static final String ID_FIELD = "id";
// Variable name changed from CHAT_FIELD to CHAT_ID_FIELD for refactoring
private static final String CHAT_ID_FIELD = "id";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Telegram api, the Chat object has the "id" field, not "chat_id". It would be convenient to leave it as is

* Refactored code - Using CHAT_ID_FIELD instead of CHAT_FIELD to change bidirectional association to unidirectional association
*/

private static final String CHAT_ID_FIELD = "chat_id";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks the Story feature of the library since the Story object in Telegram Api has the Chat object, but not chat_id. See https://core.telegram.org/bots/api#story
You will fail to deserialize any Story object

@Yukta026
Copy link
Author

I want to help the developer of this library so I did my own code review. See the github code comments. Also, why do you leave explanations to your refactor in the code comments? Keep in mind that you request to merge your code (including comments) into the upstream repository. Which means people who would like to inspect the code in the future and create their own pull requests, will have to read through your changelog in the code, when there's VCS (git) for this

Thank you for your insightful feedback on the code review. I have thoroughly reviewed all the suggested changes and made every effort to incorporate them. If you believe any additional modifications are necessary, please don't hesitate to inform me.

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

Successfully merging this pull request may close these issues.

10 participants