What does “var FOO = FOO || {}” (assign a variable or an empty object to that variable) mean in Javascript?

Your guess as to the intent of || {} is pretty close. This particular pattern when seen at the top of files is used to create a namespace, i.e. a named object under which functions and variables can be created without unduly polluting the global object. The reason why it’s used is so that if … Read more

How do I create a Python namespace (argparse.parse_args value)?

You can create a simple class: class Namespace: def __init__(self, **kwargs): self.__dict__.update(kwargs) and it’ll work the exact same way as the argparse Namespace class when it comes to attributes: >>> args = Namespace(a=1, b=’c’) >>> args.a 1 >>> args.b ‘c’ Alternatively, just import the class; it is available from the argparse module: from argparse import … Read more

Why is “using namespace X;” not allowed at class/struct level?

I don’t know exactly, but my guess is that allowing this at class scope could cause confusion: namespace Hello { typedef int World; } class Blah { using namespace Hello; public: World DoSomething(); } //Should this be just World or Hello::World ? World Blah::DoSomething() { //Is the using namespace valid in here? } Since there … Read more

C# namespace alias – what’s the point?

That is a type alias, not a namespace alias; it is useful to disambiguate – for example, against: using WinformTimer = System.Windows.Forms.Timer; using ThreadingTimer = System.Threading.Timer; (ps: thanks for the choice of Timer ;-p) Otherwise, if you use both System.Windows.Forms.Timer and System.Timers.Timer in the same file you’d have to keep giving the full names (since … Read more

Why an unnamed namespace is a “superior” alternative to static? [duplicate]

As you’ve mentioned, namespace works for anything, not just for functions and objects. As Greg has pointed out, static means too many things already. Namespaces provide a uniform and consistent way of controlling visibility at the global scope. You don’t have to use different tools for the same thing. When using an anonymous namespace, the … Read more

“Could not load type [Namespace].Global” causing me grief

One situation I’ve encountered which caused this problem is when you specify the platform for a build through “Build Configuration”. If you specify x86 as your build platform, visual studio will automatically assign bin/x86/Debug as your output directory for this project. This is perfectly valid for other project types, except for web applications where ASP.NET … Read more