Questions tagged [name-collision]

Within the context of computers and computer programming, "name collision" is the technical term for an instance in which two items have the same name within some logical enclosure. A name collision can occur in many instances, such as with the names of files in a directory, or in a program in which local variables in a function have the same name as some global variables.

The term "name collision" has been used in computer science for more than 3 decades, when referring to names in various classification systems. Most of the time, a name collision must be resolved immediately in some way, whether automatically by an operating system or compiler or manually through user input and decisions. The concept of a namespace sometimes resolves collision issues by creating different logical regions in which items with similar names can co-exist without ambiguity. In certain programming instances, a name collision might not be immediately evident, occasionally leading to hard-to-find program errors that can result from the compiler making certain assumptions about the names of items used.

An example of how a name collision can occur involves two directories full of files. If each directory contains a file named "DATA", and the contents of one directory are copied into the other, then the computer's attempts to copy the file named DATA will find that a file with the same name already exists in the target directory. This creates a name collision. In this instance, the user usually will be prompted and allowed to choose from a list of resolutions, including renaming one of the files, not copying the file or overwriting one of the files.

One commonly used solution for a name collision is the implementation of namespaces. A namespace is simply a way to define an area under which object names are contained. In the above example, a directory technically is a namespace, meaning multiple files can all have the same name as long as they are each in different directories.

From a programming perspective, a name collision can occur in situations such as multiple inheritance, overlapping variable scopes, or even with imported libraries in some languages. In general, a compiler will notice a conflict and generate a warning or error, although this might not always be the case. Other than using namespaces, collisions in many programming languages can be avoided by using qualifiers. A qualifier usually is a prefix that can be placed in front of a variable or class name to distinguish it from another variable with the same name.

75 questions
4
votes
1 answer

Early Binding of a C# COM library in VBA

Although this is a long question the coding and testing part should be really easy to reproduce. I have created two separate Class Libraries in C# and I think I am running into a name collision problem caused by existing registry keys from my…
user2140173
3
votes
0 answers

Conflicts with global types in TypeScript

I would like to use my own global types (without import, using declare type) in TypeScript. For example: // File with global types. declare type Function = (parameter: TParameter) => TResult // Another file. const someMethod =…
Michal
  • 1,755
  • 3
  • 21
  • 53
3
votes
1 answer

name collision of function in two interfaces is accepted

This is language agnostic in the sense that my question applies for any language that has the interface concept. (or swift protocols) Consider this program in C#: interface Inter1 { int Count(); } interface Inter2 { int Count(); } public…
3
votes
2 answers

Python - access module from package that is not imported through __init__.py?

I'm using one package that with __init__.py import only one variable from module, but whole module itself is not exposed. Is there a way to access that module? Lets look in this case: Whole package: test_package/ ├── __init__.py └── test_me.py Now…
Andrius
  • 19,658
  • 37
  • 143
  • 243
3
votes
1 answer

PHP: using sub-namespace class inside a namespace

Suppose I have a top-level namespace \Outer and I have another sub-namespace \Outer\Inner and I have another top-level namespace \Inner and in a class in \Outer I use Inner like this use Inner; then which Inner will be used? \Outer\Inner // (…
Mukul Anand
  • 606
  • 6
  • 24
3
votes
1 answer

Name collision between modules imported within third party modules

Suppose mine.py wants to import moduleA and moduleB but moduleA and moduleB each try to import a module called "moduleC". These are two distinct modules that both happen to be named "moduleC". When mine.py is run, depending on sys.path either…
Praxeolitic
  • 22,455
  • 16
  • 75
  • 126
3
votes
2 answers

How to access a namespace hidden by a variable in Go?

I've recently wrote the following code in Go: import ( tasks "code.google.com/p/google-api-go-client/tasks/v1" ) func tasksMain(client *http.Client, argv []string) { taskapi, _ := tasks.New(client) tasklists, _ :=…
laurent
  • 88,262
  • 77
  • 290
  • 428
3
votes
1 answer

How to copy an ActiveX control over to another sheet preventing the name change of the control

I am using the code below to copy a command button from one sheet and paste it into another: Sheets("SRC").HasACustomName.Copy Sheets("TRGT").Range("O1").PasteSpecial When I paste it, it get's renamed from HasACustomName to CommandButton1. Can I…
user1283776
  • 19,640
  • 49
  • 136
  • 276
2
votes
0 answers

Conflict between "zlib.h" header of ZLIB and CryptoPP

I use a library in my project which uses ZLIB library for compression. On the other hand I use CryptoPP library in my project. The consequence is that when compiling compiler makes a mistake and loads the zlib.h of CryptoPP instead of ZLIB. Here is…
navidcity
  • 31
  • 5
2
votes
1 answer

Spring Data MongoDB: @TextIndexed Index Already Exists With Different Options

Imagine, you have a MongoDB collection that maps to a simple entity in Spring Boot app: @Document data class Question( @Id val id: String, @TextIndexed val topic: String ) Now you want to add a new field and include it in the full-text…
2
votes
4 answers

Random string collision after using Fisher-Yates algorithm (C#)

I am doing an exercise from exercism.io, in which I have to generate random names for robots. I am able to get through a bulk of the tests until I hit this test: [Fact] public void Robot_names_are_unique() { var names = new HashSet(); …
bman
  • 23
  • 3
2
votes
0 answers

Swift 4: How to access "type(of: )", compiler accessing another method

In Xcode 9 the compiler has started mixing up methods with the the same names. In 8.3.3 this code still works. There is a method called "type" and a property called "type" in a Cocoapod class (Class A). I want to access the standard "type(of: )"…
Jay Strawn
  • 215
  • 3
  • 14
2
votes
2 answers

PHP Class Has Colliding Constructor Definitions Coming From Traits

I have 3 files which relate one to another : class/General.class.php class/Database.class.php class/User.class.php class/General.class.php contains : trait generalFunctions { private $unique_number; private $mysql_datetime; private…
Saint Robson
  • 5,475
  • 18
  • 71
  • 118
2
votes
5 answers

Java 7 interfaces and name clashing

I'm writing code in which a class implements two interfaces that happens to have two abstract methods with the same name,and two constants with the same identifier: public class Test implements A,B { public void doStuff() {} public void…
Luca
  • 1,658
  • 4
  • 20
  • 41
2
votes
0 answers

How to avoid name collisions in R: formulas, data, and new variables

I'm trying to learn to write R code that I can re-use without expecting problems in the future, specifically due to names that I assign data to in my function conflicting with names in the data passed into the function. I don't see any best…
James
  • 630
  • 1
  • 6
  • 15