namespaces

python: confusion with local class name

I have the following code: def f(): class XYZ: # ... cls = type('XXX', (XYZ, ), {}) # ... return cls I am now using it as follows: C1 = f() C2 = f() and it seems to work fine: C1 is C2 returns False, there's no conflict between the class attributes of the two classes, etc. Question 1 Why is that? How is it...

What are namespaces for ? what about usages ?

what is the purpose of namespaces ? and, more important, should they be used as objects in java (things that have data and functions and that try to achieve encapsulation) ? is this idea to far fetched ? :) or should they be used as packages in java ? or should they be used more generally as a module system or something ? ...

Where should non-member operator overloads be placed?

I want to overload operator<< for my class. Should I add this overloaded definition to the std namespace? (since the ostream operator<< is part of the std namespace) Or should I just leave it in the global namespace? In short: class MyClass { }; namespace std { ostream& operator<< ( ostream& Ostr, const MyClass& MyType ) {} } O...

History of Namespaces/Packages/Modules?

I've been researching how different languages manage organization of source code. It appears most modern languages use some form of named abstract container. What its called and how its implemented varies from one language to the next but it boils down to a programming construct that operates beyond file boundaries to group related code....

Can I hide classes in the global namespace in C#?

In a visual studio 2008 solution, I have two versions of the same class in two different namespaces. In VB, if I do this: imports MyNamespace ' ... dim x as DuplicatedClass = new DuplicatedClass() it uses MyNamespace.DuplicatedClass instead of the globally-namespaced DuplicatedClass. Meanwhile, in C#, doing this: using MyNamespace;...

doctrine2 zend framework namespaceing controllers

I'm trying to integrate the doctrine2 sandbox with a default Zend Framework App. When I try to use namespacing in the controller I get an 'Invalid controller class ("IndexController")' error This Works: use Entities\User, Entities\Address; class IndexController extends Zend_Controller_Action { ... } This does not (but should?): na...

c# using declarations - more = good or bad?

edit typos Hi, This is possibly a moronic question, but if it helps me follow best practice I don't care :P Say I want to use classes & methods within the System.Data namespace... and also the System.Data.SqlClient namespace. Is it better to pull both into play or just the parent, ie... using System.Data using System.Data.SqlClient...

PHP Autloading in Namespaces

Hey everyone, I have had a slight problem with autoloading in my namespace. As shown on the PHP manual here: http://us.php.net/manual/en/language.namespaces.rules.php you should be able to autoload namespace functions with a full qualified name e.g. \glue\common\is_email(). Thing is I have a function spl_autoload_register(array($import...

In Python, how can I access the namespace of the main module from an imported module?

Specifically, I need to get at some objects and globals from the main module in an imported module. I know how to find those things when the parent module wants some particular thing from a child module, but I can't figure out how to go in the other direction. ...

What's the significance of TLD-first domain-like identifiers?

"TLD-first domain-like identifiers" is a mouthful but that's all I can come up with. I've seen these used in various places over the years and wondered what the history/reason behind this convention is, since you might be forgiven in thinking that there is one true way to mention a domain. I don't use Java but I recall from poking arou...

C++ accessing variables from .CPP files

I'm a little fuzzy on how variable access between .cpp files works. For instance: main.cpp int main() { int a = i; return 0; } main2.cpp int i; This generates a compiler error on main.cpp, telling me there is no in i in existence. What difference then, does the "static" keyword do in this context? (I tried Googling for it,...

Two questions on main

A. Is the following attempt valid to define the entry point 'main' of a C++ standalone program? namespace{ extern int main(){return 0;} } As far as I understand, it satisifies all the criteria about 'main' in the C++ standard (external linkage, available in global namespace because of the implicit using directive). So is this progra...

What is the :: sign/operator before the class name in ruby?

Hi, in ruby, :: namespaces the module and class. But I often see :: at the beginning of the class name like the following: #snippet of gollum gem def page_class @page_class || if superclass.respond_to?(:page_class) superclass.page_class else ::Gollum::Page end end What does that :: stands for if its in the be...

C++ namespace inclusion in .cc files

I have declared a class X in X.h as follows: namespace Foo { class X{ .... }; } In X.cc I would like to define the constructors, methods for X. Do I need to enclose all my definitions inside namespace Foo {...} or prefix X as Foo::X:: for every method ? It seems that sometimes I can just say (using namespace Foo) and not mention i...

static string constants in class vs namespace for constants [c++]

I want to declare string constants that will be used across various classes in the project. I am considering two alternatives Option 1: #header file class constants{ static const string const1; }; #cpp file const string constants::const1="blah"; Option 2: #header file namespace constants{ static const string const1="bla...

Where to keep internal classes?

Suppose I'm making a new library, Jokes, with a small API. In the interest of making my API easy to use I put it in the base namespace: namespace Jokes --> public interface IJoker --> string Joke(); --> public static class Jokers --> public static IJoker NewSlapstickJoker() --> public static IJoker New...

Anonymous Namespace Ambiguity

Consider the following snippet: void Foo() // 1 { } namespace { void Foo() // 2 { } } int main() { Foo(); // Ambiguous. ::Foo(); // Calls the Foo in the global namespace (Foo #1). // I'm trying to call the `Foo` that's defined in the anonymous namespace (Foo #2). } How can I refer to something inside an anonymous namesp...

Anonymous Namespace

A recent thread on SO triggerred this. An anonymous namespace is considered to be equivalent to namespace unique { /* empty body */ } using namespace unique; namespace unique { namespace-body } I fail to recollect the exact reason as to why it is not equivalent to namespace unique { namespace-body } using namespace uniq...

xmlbeans and namespaces attributes

Hi, I'm trying to use xmlbeans to parse Google geocoder xml responses. I have an xsd which defines a subset of the KML returned by the geocoder. For reference here is an example geocoder response: <?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://earth.google.com/kml/2.0"&gt; <Response> <name>520 3rd Street San Francisco CA...

Asp.Net Mvc: Cannot access my models namespace from my view

So I have a ViewModel in the 'models' folder of my Mvc project with a namespace of 'Web.Models' (My Mvc project is called 'Web') I think its worth mentioning I have 3 other projects in my solution: Domain, Test, and Tasks. The view model is assigned properties from classes in my Domain.Entities folder. I can create a new instance of my ...