Why doesn’t ANSI C have namespaces?

For completeness there are several ways to achieve the “benefits” you might get from namespaces, in C. One of my favorite methods is using a structure to house a bunch of method pointers which are the interface to your library/etc.. You then use an extern instance of this structure which you initialize inside your library … Read more

Using std Namespace

Most C++ users are quite happy reading std::string, std::vector, etc. In fact, seeing a raw vector makes me wonder if this is the std::vector or a different user-defined vector. I am always against using using namespace std;. It imports all sorts of names into the global namespace and can cause all sorts of non-obvious ambiguities. … Read more

This is Sparta, or is it?

But why does Sparta in MakeItReturnFalse() refer to {namespace}.Place.Sparta instead of {namespace}.Sparta? Basically, because that’s what the name lookup rules say. In the C# 5 specification, the relevant naming rules are in section 3.8 (“Namespace and type names”). The first couple of bullets – truncated and annotated – read: If the namespace-or-type-name is of the … Read more

Define all functions in one .R file, call them from another .R file. How, if possible?

You can call source(“abc.R”) followed by source(“xyz.R”) (assuming that both these files are in your current working directory. If abc.R is: fooABC <- function(x) { k <- x+1 return(k) } and xyz.R is: fooXYZ <- function(x) { k <- fooABC(x)+1 return(k) } then this will work: > source(“abc.R”) > source(“xyz.R”) > fooXYZ(3) [1] 5 > … Read more

Namespace and class with the same name?

I don’t recommend you to name a class like its namespace, see this article. The Framework Design Guidelines say in section 3.4 “do not use the same name for a namespace and a type in that namespace”. That is: namespace MyContainers.List { public class List { … } } Why is this badness? Oh, let … Read more