-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
base: dev
Are you sure you want to change the base?
Conversation
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
Add getMessageId to MaybeInaccessibleMessage According to https://core.telegram.org/bots/api#maybeinaccessiblemessage
…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
…g explaining variables technique
…ing decomposing conditional technique
…ing renaming method and introducing explaining variable technique
… using explaining variables technique
…clause using explaining variables technique
…ier using renaming variables technique
…on using extract class technique
…sing moving pull-up method technique
…larization using change bidirectional association to unidirectional association technique
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 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. |
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. |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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. | ||
*/ |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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){ |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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
… using replace conditional with polymorphism technique
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. |
c4394aa
to
7df1524
Compare
bc4fd52
to
65c33e0
Compare
68a6f61
to
5fc7d88
Compare
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.