All Questions

1797
votes
34answers
575778 views

Why is "using namespace std" considered bad practice?

I've been told by others that writing using namespace std in code is wrong, and that I should use std::cout and std::cin directly instead. Why is using namespace std considered a bad practice? Is it ...
3464
votes
20answers
1454960 views

What does if __name__ == "__main__": do?

What does the if __name__ == "__main__": do? # Threading example import time, thread def myfunction(string, sleeptime, lock, *args): while True: lock.acquire() time.sleep(sleepti...
885
votes
26answers
475409 views

How do I declare a namespace in JavaScript?

How do I create a namespace in JavaScript so that my objects and functions aren't overwritten by other same-named objects and functions? I've used the following: if (Foo == null || typeof(Foo) != "ob...
1614
votes
8answers
145482 views

Should 'using' statements be inside or outside the namespace?

I have been running StyleCop over some C# code, and it keeps reporting that my using statements should be inside the namespace. Is there a technical reason for putting the using statements inside ins...
45
votes
7answers
61643 views

Parse XML with Namespace using SimpleXML

I have this as xml: <root xmlns:event="http://www.webex.com/schemas/2002/06/service/event"> <event:event> <event:sessionKey></event:sessionKey> <event:s...
87
votes
7answers
13335 views

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

Looking at an online source code I came across this at the top of several source files. var FOO = FOO || {}; FOO.Bar = …; But I have no idea what || {} does. I know {} is equal to new Object() a...
559
votes
8answers
147204 views

Can someone explain __all__ in Python?

I have been using Python more and more, and I keep seeing the variable __all__ set in different __init__.py files. Can someone explain what this does?
88
votes
15answers
69428 views

Using std Namespace

There seem to be different views on using 'using' with respect to the std namespace. Some say use ' using namespace std', other say don't but rather prefix std functions that are to be used with ' st...
97
votes
9answers
52495 views

"using namespace" in c++ headers

In all our c++ courses, all the teachers always put using namespace std; right after the #includes in their .h files. This seems to me to be dangerous since then by including that header in another pr...
53
votes
12answers
62307 views

Using Xpath With Default Namespace in C#

I've got an XML document with a default namespace. I'm using a XPathNavigator to select a set of nodes using Xpath as follows: XmlElement myXML = ...; XPathNavigator navigator = myXML.CreateNavi...

Previous Next