A “big picture” question.

The unasked question never gets answered. I don’t know if you can practically use the following suggestion, but it may be clarifying anyway. When an amateur develops code incorrectly, s/he sometimes ends up with a code object that doesn’t run because of intermediate compiler optimizations. As an example, you could ask a high school class to individually build a 26x26 grid, with the first line having abcdef…xyz; the second line having zabcd…wxy, and so on. This often results in code that has been corrected, but will not run correctly because of pre-mature compiler optimizations. Another task that might illustrate this artifact of program development might be to have amateurs write a function that raises a^b mod x. When programming in a C++ environment, this is monitored by keeping track of “commit charges.” I’m imagining the following solution. Instead of implementing compiler optimizations at every execution, have python run completely interpretive like old Basic. Then introduce a command line switch, that tells python you are ready to employ compiler optimizations. There exists a -O switch; there is also a “compileall,” command, both of which introduce optimizations. It isn’t clear what each does that is different, or how to turn all optimizations off for purposes of testing (usually bad) logic. Would python benefit as a language by introducing a clearer deliberation as to when the “commit charge,” occurs? I ask this only to suggest clarity of thought… it might be impractical to disambiguate them all, after “killing yourselves,” making the language run like a bat out of hell already. Thanks for all you do, James Johnson

On Fri, 10 Jun 2022 at 21:20, James Johnson <jj126979@gmail.com> wrote:
The unasked question never gets answered. I don’t know if you can practically use the following suggestion, but it may be clarifying anyway.
When an amateur develops code incorrectly, s/he sometimes ends up with a code object that doesn’t run because of intermediate compiler optimizations.
Got any examples of that happening in Python? ChrisA

On Wed, Jun 08, 2022 at 06:51:54AM -0500, James Johnson wrote:
When an amateur develops code incorrectly, s/he sometimes ends up with a code object that doesn’t run because of intermediate compiler optimizations.
If that happens, that's a bug in the compiler. Optimizations should never change the meaning of code. If you have an example of this, where the compiler optimization changes the meaning of Python code beyond what is documented, please raise a bug report for it. But I doubt you will find any, because Python performs very, very few optimizations of the sort you are referring to. -- Steve

Steven D'Aprano writes:
On Wed, Jun 08, 2022 at 06:51:54AM -0500, James Johnson wrote:
When an amateur develops code incorrectly, s/he sometimes ends up with a code object that doesn’t run because of intermediate compiler optimizations.
If that happens, that's a bug in the compiler. Optimizations should never change the meaning of code.
This isn't quite true. Languages (mostly low-level) frequently leave behavior of legal syntax partly undefined in order to allow efficient implementation on various architectures, or because it's unclear how it will be used in the future (function annotations, I be lookin' at you!)
If you have an example of this, where the compiler optimization changes the meaning of Python code beyond what is documented, please raise a bug report for it.
OK, you've mostly taken care of the letter of my comment. But I still think it's worth pointing out that the documentation is frequently incomplete for various reasons.
But I doubt you will find any, because Python performs very, very few optimizations of the sort you are referring to.
True, although it might in the future.
participants (4)
-
Chris Angelico
-
James Johnson
-
Stephen J. Turnbull
-
Steven D'Aprano