java-math-library icon indicating copy to clipboard operation
java-math-library copied to clipboard

Increase the usage of compound assignment operators

Open elfring opened this issue 2 years ago • 8 comments

:eyes: Some source code analysis tools can help to find opportunities for improving software components. :thought_balloon: 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')

elfring avatar Dec 19 '21 16:12 elfring

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.

TilmanNeumann avatar May 14 '22 10:05 TilmanNeumann

If the diff created by your transformation script is so …

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

elfring avatar May 14 '22 17:05 elfring

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

TilmanNeumann avatar May 14 '22 17:05 TilmanNeumann

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

elfring avatar May 14 '22 17:05 elfring

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

TilmanNeumann avatar May 14 '22 20:05 TilmanNeumann

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).

elfring avatar May 15 '22 06:05 elfring

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.

TilmanNeumann avatar May 15 '22 13:05 TilmanNeumann

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

elfring avatar May 15 '22 13:05 elfring