globals

Python - What priority does global have?

南楼画角 提交于 2019-11-29 11:52:08
I'm a bit confused about globals when it comes to packages using other packages. From a quick google search; there's not much that explains. Simply put: at what level is a variable "globalized" when using global ? Is it at the module level, package level, or interpreter level? Ie, in a setup such as this: <Package> |- __init__.py |- Module.py |- Module2.py and there is a global statment used within Module.py, is the variable globalized for just that module, or the entire package (including Module2.py and or __init__.py), or at the interperter level (for anything being run in the interpreter).

PHP - performance and memory issue with global variables

不打扰是莪最后的温柔 提交于 2019-11-29 08:46:33
Hypothetical situation: I'm running a complex site in php, and i use a lot of global variables. i could store the variables in an existing global scope, say $_REQUEST['userInfo'] , $_REQUEST['foo'] , and $_REQUEST['bar'] etc. and put a lot of different things into the request scope (which would be appropriate use, as these data refer to the request itself). or i could keep using lines like global $userInfo, $foo, $bar; in most of my functions. is there a performance hit, or a difference in memory usage for either solution? one is a little easier to type... so is there a best-practices

Is it safe to modify the output of globals()?

若如初见. 提交于 2019-11-29 03:03:20
The documentation for the locals() function specifically warns not to modify its output, as interpreters may not reflect changes in the local scope. I'm assuming that means the Python spec doesn't require it, even though it works in CPython. I'd like to know if this is the same for globals(). There's no warning in the documentation , but I find it strange that this would differ as each function apparently performs the same action on a different scope. If it's safe, modifying globals()' output would improve the simplicity and compatibility of a project I'm working on. Modifying locals() doesn't

What is meant by “leaking” into global scope?

寵の児 提交于 2019-11-28 07:33:58
A while ago, I offered-up a JavaScript design pattern (the Module Pattern - see below) that I got from a John Resig example as part of a solution to someone’s question and I received the following comment: “…that pattern is a bit over engineered and not that good. Still leaking into global-scope. and your not opening yourself to async loaders. But it is better then just ad-hoc coding !” So… If “leaking” into global scope means “your object gets appended to the browsers window (object)”…then everything already gets appended (globally): This “leaks” into global scope: window.jQuery …just call:

Python - What priority does global have?

好久不见. 提交于 2019-11-28 05:03:10
问题 I'm a bit confused about globals when it comes to packages using other packages. From a quick google search; there's not much that explains. Simply put: at what level is a variable "globalized" when using global ? Is it at the module level, package level, or interpreter level? Ie, in a setup such as this: <Package> |- __init__.py |- Module.py |- Module2.py and there is a global statment used within Module.py, is the variable globalized for just that module, or the entire package (including

Objective C defining UIColor constants

陌路散爱 提交于 2019-11-27 18:46:28
I have a iPhone application with a few custom-defined colors for my theme. Since these colors will be fixed for my UI, I would like to define the colors in a class to be included (Constants.h and Constants.m). How do I do that? (Simply defining them does not work because UIColors are mutable, and would cause errors - Initalizer not constant). /* Constants.h */ extern UIColor *test; /* Constants.m */ UIColor *test = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]; Thanks! A UIColor is not mutable. I usually do this with colors, fonts and images. You could easily modify it to use

Is it safe to modify the output of globals()?

我与影子孤独终老i 提交于 2019-11-27 17:20:53
问题 The documentation for the locals() function specifically warns not to modify its output, as interpreters may not reflect changes in the local scope. I'm assuming that means the Python spec doesn't require it, even though it works in CPython. I'd like to know if this is the same for globals(). There's no warning in the documentation, but I find it strange that this would differ as each function apparently performs the same action on a different scope. If it's safe, modifying globals()' output

3 questions about extern used in an Objective-C project

北慕城南 提交于 2019-11-27 06:41:51
When I use the word extern before a method or variable declaration, am I making it global and therefore readable/writable/usable over the entire project ? If I use extern before a keyword, is there any chance it is still not accessible by part of my project ? For example, only by subclasses.. such as when I use "protected". extern is a C keyword, right? Is there an equivalent in Objective-C? I actually don't understand why they use a C keyword in an Objective-C project. thanks 1) you're specifying its linkage. extern linkage allows you or any client to reference the symbol. regarding global

What is meant by “leaking” into global scope?

守給你的承諾、 提交于 2019-11-27 01:56:37
问题 A while ago, I offered-up a JavaScript design pattern (the Module Pattern - see below) that I got from a John Resig example as part of a solution to someone’s question and I received the following comment: “…that pattern is a bit over engineered and not that good. Still leaking into global-scope. and your not opening yourself to async loaders. But it is better then just ad-hoc coding !” So… If “leaking” into global scope means “your object gets appended to the browsers window (object)”…then

Where are constant variables stored in C?

孤街浪徒 提交于 2019-11-26 19:43:30
I wonder where constant variables are stored. Is it in the same memory area as global variables? Or is it on the stack? How they are stored is an implementation detail (depends on the compiler). For example, in the GCC compiler, on most machines, read-only variables, constants, and jump tables are placed in the text section. wrapperm Depending on the data segmentation that a particular processor follows, we have five segments: Code Segment - Stores only code, ROM BSS (or Block Started by Symbol) Data segment - Stores initialised global and static variables Stack segment - stores all the local