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
129
votes
13 answers

What should I do if two libraries provide a function with the same name generating a conflict?

What should I do if I have two libraries that provide functions with equivalent names?
qeek
  • 2,010
  • 2
  • 16
  • 23
75
votes
5 answers

Why are my dplyr group_by & summarize not working properly? (name-collision with plyr)

I have a data frame that looks like this: #df ID DRUG FED AUC0t Tmax Cmax 1 1 0 100 5 20 2 1 1 200 6 25 3 0 1 NA 2 30 4 0 0 150 6 65 Ans so on. I want to summarize some…
Amer
  • 2,131
  • 3
  • 23
  • 38
21
votes
1 answer

Name collision by module import in Angular 2 - is there a way to prevent it

I've almost caused a name collision, because I've created a class with common name Message, which already exists in PrimeNG: import {Message} from "primeng/primeng"; import {Message} from "./dto"; Because it is my code, I could simply rename the…
9ilsdx 9rvj 0lo
  • 7,955
  • 10
  • 38
  • 77
12
votes
3 answers

How to unmask a function in R, due to name collisions on searchpath

When I loaded package debug to debug a script with zoo objects, I got trouble: function index from zoo got masked by debug package. How can I unmask index? In general, how to deal with these name colliding problems? We just do not use debug package…
ahala
  • 4,683
  • 5
  • 27
  • 36
10
votes
3 answers

How to import two classes with the same name in different packages?

I want to import these two classes, both named Query - one a JDO class, the other a JPA class, to use in different methods in the same class. import javax.jdo.Query; import javax.persistence.Query; Is there a way to globally import both of them at…
Ment
  • 221
  • 3
  • 9
10
votes
1 answer

Can't create private classes with same name in different modules

Official docs on visibility modifiers in Kotlin say that package-level elements marked private are be visible only in the module in which they are declared. So class A declared in Module1.kt isn't visible in Module2.kt. But if I try to add to…
netimen
  • 4,199
  • 6
  • 41
  • 65
9
votes
2 answers

Name collision between c++ library namespace and C linux function

The Linux header defines the function meta, and the C++ metaprogramming library meta puts all its code in the global namespace meta. How can I use both in the same C++ program (not necessarily the same TU but that would be nice)? Is…
gnzlbg
  • 7,135
  • 5
  • 53
  • 106
7
votes
3 answers

Is there anything wrong with using static const structs to limit name collisions of constants in C?

For example, if I were to create a hierarchical static const struct like this in a header (.h) file: static const struct { struct { char STATIC /* = 0 */; char DYNAMIC /* = 1 */; } ALLOCATION; struct { char TABLE…
Matt
  • 21,026
  • 18
  • 63
  • 115
6
votes
1 answer

Java name collision between variable and top-level package name

Triggered by this bug report AVRO-1814 I reduced the problem to this minimal example case in Java that simply shows the core of the effect. package nl.basjes.experiment; public class NamingClash { String nl = "foo"; public void test() { …
Niels Basjes
  • 10,424
  • 9
  • 50
  • 66
5
votes
0 answers

How to handle field collisions from different logging sources in Elasticsearch?

We send logs from a variety of services running in a Kubernetes cluster to Elasticsearch via Filebeat. Some of these services we develop ourselves, others are third-party. We use dynamic mapping in our indices. We've hit an issue where sometimes a…
Matt R
  • 9,892
  • 10
  • 50
  • 83
5
votes
4 answers

javascript function name collision

I have two JavaScript files that contain a jQuery function with the same name $(). How can I distinguish between the two identically named functions?
user368038
  • 265
  • 1
  • 5
  • 16
4
votes
3 answers

Python 3 import conflicts with internal "parser"

. ├── gen.py ├── lexer │   ├── engine.py | └── ... └── parser ├── engine.py └── ... I'm writing my compiler project, but now i'm stuck with python import conflicts. In gen.py, I want to import some function for code generation, like…
Mike Dog
  • 74
  • 1
  • 6
4
votes
1 answer

Calling non-member operator overloads

Given the following code: #include #include #include template constexpr bool ostreamable_with = false; template // If there's user-defined overloads constexpr bool…
ABu
  • 10,423
  • 6
  • 52
  • 103
4
votes
1 answer

SQLite select with string equality where value is same as column name?

I have an SQLite (v3.8.7.1 2014-10-29) database with a table containing names of locally installed software packages including details of version, date installed, software home page URL, etc. Now the problem has arisen that one of the packages (CPAN…
J G Miller
  • 243
  • 1
  • 2
  • 8
4
votes
5 answers

How solve module name collision in Python?

I have a module named websocket. For this module I want some tests and for these tests I pip install the appropriate module. The problem is that the installed module has the exact same name as my own module. Project structure: websocket-server …
Pithikos
  • 18,827
  • 15
  • 113
  • 136
1
2 3 4 5