Skip to content

[SHRINKWRAP-538] Resolving verbose or redundant code constructs - #181

Merged
petrberan merged 1 commit into
shrinkwrap:mainfrom
khermano:SHRINKWRAP-538_from_main
Nov 1, 2024
Merged

petrberan merged 1 commit into
shrinkwrap:mainfrom
khermano:SHRINKWRAP-538_from_main

Conversation

@khermano

@khermano khermano commented Oct 1, 2024

Copy link
Copy Markdown
Contributor

for (Package pack : packages) {
classExpression.append("|");
classExpression.append("(.*" + pack.getName().replaceAll("\\.", "\\.") + ".*)");
classExpression.append("(.*").append(pack.getName().replaceAll("\\.", ".")).append(".*)");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why the change of + to .append? In other instances in this PR you're doing the opposite.

Wouldn't it be also better to have just a single line of classExpression.append("|(.*" + pack.getName().replaceAll("\\.", ".")) + ".*)");?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

.append() is the recommended way how to work with StringBuilder. It avoids creating unnecessary intermediate String objects. On the other hand, the recommended way to work with String is to use "+".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

True, missed that. My comment regarding the single line append still stands though

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That happens and I understand, but it's not a single line since it's inside the for loop.

@khermano
khermano force-pushed the SHRINKWRAP-538_from_main branch from af1930c to 8f8d6bd Compare October 15, 2024 12:23
for (Package pack : packages) {
classExpression.append("|");
classExpression.append("(.*" + pack.getName().replaceAll("\\.", "\\.") + ".*)");
classExpression.append("|").append("(.*").append(pack.getName().replaceAll("\\.", ".")).append(".*)");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still would very much prefer .append("|(.*") over .append("|").append("(.*")

@khermano
khermano force-pushed the SHRINKWRAP-538_from_main branch from 8f8d6bd to f2cd18b Compare October 23, 2024 08:13

@petrberan petrberan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@petrberan
petrberan merged commit 01e3af3 into shrinkwrap:main Nov 1, 2024
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.

2 participants