global

How can I avoid global state?

So, I was reading the Google testing blog, and it says that global state is bad and makes it hard to write tests. I believe it--my code is difficult to test right now. So how do I avoid global state? The biggest things I use global state (as I understand it) for is managing key pieces of information between our development, acceptance...

Best way to tackle global hotkey processing in c#?

Hi all I'd like to have multiple global hotkeys in my new app (to control the app from anywhere in windows), and all of the given sources/solutions I found on the web seem to provide with a sort of a limping solution (either solutions only for one g.hotkey, or solutions that while running create annoying mouse delays on the screen). Do...

global variables in php not working as expected

I'm having trouble with global variables in php. I have a $screen var set in one file, which requires another file that calls an initSession() defined in yet another file. The initSession() declares "global $screen" and then processes $screen further down using the value set in the very first script. How is this possible? To make thing...

Python: How to make a cross-module variable?

The __debug__ variable is handy in part because it affects every module. If I want to create another variable that works the same way, how would I do it? The variable (let's be original and call it 'foo') doesn't have to be truly global, in the sense that if I change foo in one module, it is updated in others. I'd be fine if I could set...

Do you use the "global" statement in Python ?

I was reading a question about the Python global statement ( "Python scope" ) and I was remembering about how often I used this statement when I was a Python beginner (I used global a lot) and how, nowadays, years later, I don't use it at all, ever. I even consider it a bit "un-pythonic". Do you use this statement in Python ? Has your u...

capturing global keypresses in Java

So I want to trigger an event (pausing/unpausing some media) whenever the user presses spacebar anywhere in the my Swing app. Since there are so many controls and panels that could have focus, its not really possible to add keyevents to them all(not to mention gross). So I found KeyboardFocusManager.getCurrentKeyboardFocusManager()....

defining structures globally in c++

there was a somewhat detailed thread (228684) on how to globally (using extern struct) declare a structure that could be seen in more than 1 c++ file, but I can not figure out exactly how to do it (there was a lot of discussion about do this, do that, maybe do this, try this, etc...). couuld someone please post a very simple example of...

Static vs global in terms of speed and space consumption in C

I would like to know difference between static variables and global variables in terms of access speed and space consumption. (If you want to know my platform: gcc compiler on Windows. (I am using Cygwin with Triton IDE for ARM7 embedded programming on windows. Triton comes with gcc compiler on Java platform which can be run on Windows.)...

What is the difference between a static global and static volatile variable?

I have used a static global variable and a static voltalile variable in file scope, both are updated by an ISR and a main loop and main loop checks the value of the variable. here during optimization neither global vriable nor the volatile variable are optimized. So instead of using a volatile variable a global variable solves the probl...

JavaScript - check if in global context

When a function is attached to an object and called: function f() { return this.x; } var o = {x: 20}; o.func = f; o.func(); //evaluates to 20 this refers to the object that the function was called as a method of. It's equivalent to doing f.call(o). When the function is called not as part of an object, this refers to the global object...

C++ variable with same name, context : global and private,

In the following code, g++ gives this error : 1.cpp: In member function void W::test()': 1.cpp:6: error: int F::glob' is private 1.cpp:19: error: within this context But, shouldn't the globally declared variable 'glob' be used here, instead of the "private" "glob"? #include <iostream.h> int glob; class F { int g...

Does there exist a publicly accessible parsable Country/Country Code list?

I find that I always find it useful to have a list of all Countries and their country codes. If someone provided it in multiple formats (eg: SQL, DDL, Xml, CSV, JSON, YAML...). I've found sites that attempt to sell a list of countries but that seems crazy to me. Is there an open source project that I'm overlooking? If there isn't does a...

C/C++ Performance Globals vs Get/Set Methods

I saw this question asking about whether globals are bad. As I thought about the ramifications of it, the only argument I could come up with that they're necessary in some cases might be for performance reasons. But, I'm not really sure about that. So my question is, would using a global be faster than using a get/set method call? G-...

Implementation in global functions, or in a class wrapped by global functions

I have to implement a set of 60 functions, according to the predefined signatures. They must be global functions, and not some class's member functions. When I implement them, I use a set of nicely done classes provided by 3rd party. My implementation of most functions is quite short, about 5-10 lines, and deals mostly with different ac...

How can I know which feature is clicked in a Windows Mobile application?

How can I know which feature (menu items, buttons, etc.) is clicked in a Windows Mobile application? I need to create an app which listens to user clicks globally, much like what windows global hooks does and I need to know which part/control of every application the user clicked on. TIA! ...

How do I get past this variable initialization problem?

How do I get past this variable initialization problem? If I only could figure out how to only initialize them only once... * Main.cpp : main project file. /************************** Begin Header **************************/ #include "stdafx.h" //Required by Visual C ++ #include <string> //Required to use strings #include <iostr...

Global vs Singleton in .NET

I have a very common situation here. And for years I haven't found if what i am doing is RIGHT by industry standards.Consider an application which connects to the database, but where the connection string instead of being stored in some file/setting is being passed as a command line parameter at startup OR the database is browsed to at t...

Making a global variable accessible for every function inside a class (PHP5)

I have a variable on the global scope that is named ${SYSTEM}, where SYSTEM is a defined constant. I've got a lot of classes with functions that need to have access to this variable and I'm finding it annoying declaring global ${SYSTEM}; every single time. I tried declaring a class variable: public ${SYSTEM} = $GLOBALS[SYSTEM]; but this...

python, dictionary and int error

I have a very frustrating python problem. In this code fixedKeyStringInAVar = "SomeKey" def myFunc(a, b): global sleepTime global fixedKeyStringInAVar varMe=int("15") sleepTime[fixedKeyStringInAVar] = varMe*60*1000 #more code Now this works. BUT sometimes when i run this fuction i get TypeError: 'int' object does...

Share variables between functions in PHP without using globals

I have a class for interacting with a memcache server. I have different functions for inserting, deleting and retrieving data. Originally each function made a call to memcache_connect(), however that was unnecessary, eg. mc->insert() mc->get() mc->delete() would make three memcache connections. I worked around this by creating a cons...