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

Increase the usage of compound assignment operators #29

Open
elfring opened this issue Dec 19, 2021 · 8 comments
Open

Increase the usage of compound assignment operators #29

elfring opened this issue Dec 19, 2021 · 8 comments

Comments

@elfring
Copy link

elfring commented Dec 19, 2021

👀 Some source code analysis tools can help to find opportunities for improving software components.
💭 I propose to increase the usage of compound operators accordingly.

Would you like to integrate anything from a transformation result which can be generated by a command like the following?
(:point_right: Please check also for questionable change suggestions because of an evolving search pattern.)

lokal$ perl -p -i.orig -0777 -e 's#\b(?<target>\S+)\s*=\s*\k<target>[ \t]*(?<operator>[+\-*/%^]|&(?!&)|\|(?!\|)|<<|>>>?)#$+{target} $+{operator}=#gm' $(find ~/Projekte/java-math-library/lokal -name '*.java')
@TilmanNeumann
Copy link
Owner

Sorry, haven't seen this for a while. I'ld have thought that I am using compound operators pretty often, particularly at places where performance matters.

If the diff created by your transformation script is so big that I can't review it in a reasonable amount of time then I won't accept it.

@elfring
Copy link
Author

elfring commented May 14, 2022

If the diff created by your transformation script is so …

Would you dare to take another look at the generated change suggestion?

@TilmanNeumann
Copy link
Owner

I'm a stupid Windows user, no Perl here. Give me a hint please ;-)

@elfring
Copy link
Author

elfring commented May 14, 2022

How do you think about to try the shown search and replace pattern out by using tools you feel more familiar with?

@TilmanNeumann
Copy link
Owner

I can't because I do not understand what it is doing. Please explain me what it does.

@elfring
Copy link
Author

elfring commented May 15, 2022

I propose to become more familiar with advanced applications of regular expressions here.
(By the way: It can be nicer and safer to achieve similar transformations with the help of computation tree logic and corresponding semantic patch languages.)

The search pattern tries to find improvable assignments (in Java source code).
Thus named capturing groups are applied so that captured contents can be used for possible text replacements.

The shown Perl command would adjust selected files in-place (after a file backup was performed).

@TilmanNeumann
Copy link
Owner

Thanks for the explanation. Actually I am roughly familiar with regular expressions but the command you posted is not that easy to understand. One day I might install a Linux subsystem and give it a go.

@elfring
Copy link
Author

elfring commented May 15, 2022

The shown Perl command example is portable.
Thus it can generally be tried out (on demand) in various system environments, can't it? 🤔

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

2 participants