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 augmented assignment statements #266

Open
elfring opened this issue Sep 26, 2021 · 13 comments
Open

Increase the usage of augmented assignment statements #266

elfring opened this issue Sep 26, 2021 · 13 comments

Comments

@elfring
Copy link

elfring commented Sep 26, 2021

I suggest to use an augmented assignment statement also at the following place in the function “getData” of the script “guider.py”.

                 # composite packets #
-                data = data + output
+                data += output
 
                 if not output:
@iipeace
Copy link
Owner

iipeace commented Sep 27, 2021

It looks better! 👍

@elfring
Copy link
Author

elfring commented Oct 2, 2021

I propose to reconsider and improve also special string concatenations which can be found with the help of a search pattern like the following.

[Markus_Elfring@fedora guider]$ grep --perl-regexp --count "(\w+)\s*=\s*('|\")%s.*%s.*\2\s*%\s*\(\1,.+\)" guider.py
113

Example:

                         if SysMgr.lineLength > nowLen + len(nextCall):
-                            userCall = '%s%s' % (userCall, nextCall)
+                            userCall += nextCall
                             nowLen += len(nextCall)

Would you like to adjust any more questionable data processing details? 🤔

@iipeace
Copy link
Owner

iipeace commented Oct 2, 2021

I agree with you!
I'll fix them!

@elfring
Copy link
Author

elfring commented Oct 2, 2021

Would you like to use any development tools which can help a bit more to perform mass source code transformations? 🤔

@iipeace
Copy link
Owner

iipeace commented Oct 2, 2021

Yes, I would like to use those tools if I can use them.
Could you recommend any tools?

@elfring
Copy link
Author

elfring commented Oct 2, 2021

  • Something can be achieved by the application of advanced regular expressions to some degree.
  • Do you know any development tools which can take regex captures better into account?
  • How do you think about to extend possibilities for collateral evolution by means of variations with computation tree logic?

@elfring
Copy link
Author

elfring commented Oct 2, 2021

Thanks for another source code improvement.

I guess that there are more remaining update candidates to consider according to the discussed transformation pattern.

Additional change suggestion:

                         else:
-                            userCall = '%s\n%s %s' % \
-                                (userCall, ' ' * indentLen, nextCall)
+                            userCall += '\n%s %s' % (' ' * indentLen, nextCall)
                             nowLen = indentLen + len(nextCall)

Would you find development tools (like the following) helpful?

@elfring
Copy link
Author

elfring commented Oct 9, 2021

Yes, I would like to use those tools if I can use them.

Would you like to integrate anything from a source code 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]] = :[a] + :[[b]]' ':[a] += :[b]' $(find /home/altes_Heim2/elfring/Projekte/guider/lokal -name '*.py')

@iipeace
Copy link
Owner

iipeace commented Oct 15, 2021

I checked this result :)
some lines are wrong but other is useful :)

+++ guider.py
@@ -20727,12 +20727,12 @@
                     data2 = ord(source[count])

                 thisVal = data1*256 + data2
-                sum = sum + thisVal
+                sum += thisVal
                 sum = sum & 0xffffffff # Necessary?
-                count = count + 2
+                count += 2

             if countTo < len(source):
-                sum = sum + ord(source[len(source) - 1])
+                sum += ord(source[len(source) - 1])
                 sum = sum & 0xffffffff # Necessary?

             sum = (sum >> 16)  +  (sum & 0xffff)
@@ -62803,7 +62803,7 @@
                 if sym.endswith(Debugger.RETSTR):
                     rsym = sym
                 else:
-                    rsym = sym + Debugger.RETSTR
+                    rsym += Debugger.RETSTR

                 # add return stats #
                 if rsym in instance.callTable and \
@@ -67605,7 +67605,7 @@
                         struct.unpack('HHHHIII', target)

                     # get verdef strings #
-                    soffset = offset + vd_aux
+                    soffset += vd_aux
                     for vidx in range(vd_cnt):
                         starget = verdef_section[soffset:soffset+sentsize]
                         vda_name, vda_next = \
@@ -67643,7 +67643,7 @@
                         struct.unpack('HHIII', target)

                     # get verneed strings #
-                    soffset = offset + entsize
+                    soffset += entsize
                     for vidx in range(vn_cnt):
                         starget = verneed_section[soffset:soffset+entsize]
                         vna_hash, vna_flags, vna_other, vna_name, vna_next = \

@elfring
Copy link
Author

elfring commented Oct 16, 2021

some lines are wrong but other is useful

💭 Would you like to integrate anything from a source code transformation result which can be generated also by a command like the following?
(:point_right: Update candidates in 26 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 /home/altes_Heim2/elfring/Projekte/guider/lokal -name '*.py')

@elfring
Copy link
Author

elfring commented Oct 16, 2021

How do you think about to share insights for the evolution of run time characteristics (eventually also for a software component like “Sly Lex Yacc”) together with adjustments for discussed implementation details? 🤔

@elfring
Copy link
Author

elfring commented Oct 30, 2021

💭 Do any factors hinder the wider application of functionality which became generally available with Python 2?

@iipeace
Copy link
Owner

iipeace commented Oct 31, 2021

I also like the augmented assignment expression :)
I already applied it in manual and using your scripts.

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