Coder Social home page Coder Social logo

Comments (6)

GoogleCodeExporter avatar GoogleCodeExporter commented on May 18, 2024
Attached an XML file of the example program mentioned above.

Original comment by [email protected] on 10 Jun 2012 at 4:06

Attachments:

from blockly.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 18, 2024
Added patch to fix issue.

Note that this creates a global statement for any variable that is a) assigned, 
b) used in a 'change _ by _' statement, or c) used as the control variable of a 
for or for-each loop.

Original comment by [email protected] on 10 Jun 2012 at 5:49

Attachments:

from blockly.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 18, 2024
Great bug, greater patch! Modified it slightly so potential new blocks will be 
covered. Your patch is superior in that it only makes global any assigned 
variables (in setters), whereas ours catches all variables, even just getters. 
For the educational environment, we feel that consistency is better.

Original comment by [email protected] on 10 Jun 2012 at 7:23

  • Changed state: Fixed

from blockly.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 18, 2024
Cool, thanks for accepting. One thing is I'm not sure what you mean by 
"consistency is better."

Are you talking about consistency in the behaviour of the Python program when 
it runs? Or that it's simply better to list all variables in 'globals' for 
clarity (regardless of whether it is redundant)?

Because if you mean the latter, I take your point. But if you mean the former, 
then please note that my patch is equivalent in terms of runtime behaviour: if 
a variable is not assigned in a function, then Python will implicitly treat it 
as global, so there is no need to explicitly label it as 'global'. So using my 
example above, your patch will mean that 'global x' appears in the printx 
function, even though it is unnecessary to do so.

But I do take your point: it is much less likely to break in the future if you 
simply declare all variables as global instead of trying to be clever as I was.

Original comment by [email protected] on 10 Jun 2012 at 7:40

from blockly.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 18, 2024
We were thinking of consistency for users.  Imagine a user sees this code:

def foo():
  global x
  x += 1
  print y

Then they add "y += 1" to the generated Python function and wonder why it just 
blew up.  That's weird even for a seasoned programmer who's unfamiliar with 
Python's whacky/awesome/fearsome scope system.  Just pretending that all 
variables need to be listed is simpler to understand.

Original comment by [email protected] on 10 Jun 2012 at 7:47

from blockly.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 18, 2024
Right, got you. That makes sense.

Original comment by [email protected] on 10 Jun 2012 at 8:55

from blockly.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.