sly icon indicating copy to clipboard operation
sly copied to clipboard

Increase the usage of augmented assignment statements

Open elfring opened this issue 4 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 augmented assignment statements 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.)

[Markus_Elfring@fedora lokal]$ ./comby -diff ':[[a]] = :[[_]] + :[[b]]' ':[a] += :[b]' $(find ~/Projekte/SLY/lokal -name '*.py')
…
+++ /home/Markus_Elfring/Projekte/SLY/lokal/sly/yacc.py
@@ -1231,7 +1231,7 @@
                 lr_index = p.lr_index
                 j = state
                 while lr_index < p.len - 1:
-                    lr_index = lr_index + 1
+                    lr_index += 1
                     t = p.prod[lr_index]
 
                     # Check to see if this symbol and state are a non-terminal transition
…

elfring avatar Oct 10 '21 17:10 elfring

:thought_balloon: Would you like to apply a source code transformation result which can be generated also by a command like the following? (:point_right: Update candidates in 12 lines)

[Markus_Elfring@fedora lokal]$ perl -p -i.orig -0777 -e 's/^(?<indentation>\s+)(?<target>\S+)\s*=\s*\k<target>\s*(?<operator>[+\-%&|^@]|\*\*?|\/\/?|<<|>>)/$+{indentation}$+{target} $+{operator}=/gm' $(find ~/Projekte/SLY/lokal -name '*.py')

elfring avatar Oct 16 '21 15:10 elfring

Does this make any different at all in SLY performance?

dabeaz avatar Oct 16 '21 15:10 dabeaz

I guess that a corresponding run time difference would be measurable. Can you find further software fine-tuning desirable then? :thinking:

elfring avatar Oct 16 '21 15:10 elfring

Why do these changes matter?

dabeaz avatar Oct 16 '21 15:10 dabeaz

:thought_balloon: I suggest to reconsider your development concerns also according to information from the Python enhancement proposal 577 (from 2018-05-14).

elfring avatar Oct 16 '21 15:10 elfring

Why does this matter?

dabeaz avatar Oct 16 '21 15:10 dabeaz

Can you accept the explanation from the Python documentation (which you probably know already)?

“… In the augmented version, x is only evaluated once. Also, when possible, the actual operation is performed in-place, meaning that rather than creating a new object and assigning that to the target, the old object is modified instead. …”

:thought_balloon: Do you accordingly expect positive effects for the software run time characteristics?

elfring avatar Oct 16 '21 16:10 elfring

@jpsnyder : :thought_balloon: Would you confirm that a synthetic version of the human mind can produce suggestions that are valid in the context of software development?

hadware avatar Oct 25 '21 08:10 hadware