Main Content

Default local - a good choice by the author of Python

Archive - Originally posted on "The Horse's Mouth" - 2012-10-08 07:09:58 - Graham Ellis

Although it would be convenient at times to be able to refer to any variable anywhere in your program, this is not how most languages work by default. And they're designed that way! That's to avoid confusion as a program grows, when there's a strong possibility of several programmers on the same project happening to choose the same name to use within their own are (module / function / subroutine). It also makes for cleaner code, as it avoids anyone who's writing or updating the program being tempted to make use of a variable from another area without passing it around properly - i.e. it avoids adding a long distance dependency that will be trouble during code maintenance.

Example in Python - [here] - from yesterday's learning to program in Python course.