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
0
votes
2 answers

How to avoid a name collision between a boolean and a method which returns it

Let's say that I've got a class which handles animations. Inside of this class is a boolean called isLooped and a function which returns this boolean. My question is, what can I do to avoid calling the function and variable the same thing? I have…
0
votes
1 answer

How to tell RubyMine what class I'm using when there are name conflicts?

In a Padrino project, Ruby itself is smart enough to know I'm referencing my Page model instead of the paginator's Page class. But RubyMine gets lost and thinks I'm dealing with the pagination and insists in marking some errors (as new arguments…
igorsantos07
  • 4,456
  • 5
  • 43
  • 62
0
votes
1 answer

How should I deal with namespace and classname collisions

My program has a Model Foo and a namespace that I want to also call Foo. They both make sense to me, but I want to avoid namespace and classname collisions. Which one should I change? The namespace App.Foo or the Model App.Models.Foo? Note: I'm…
danielr
  • 130
  • 1
  • 8
0
votes
2 answers

JAXB/XJC external binding for renaming versus multiple XSD compile

(I've already googled it and done a search here and found no answer, maybe I'm using the wrong keywords...) To make it simple, I have two schemas: a.xsd:
fscherrer
  • 218
  • 3
  • 8
0
votes
2 answers

Name conflict between member function and class name

I'm writing a chess program with wxWidgets. At one point, I have a subclass of wxGLCanvas, and it makes use of a Move class I wrote. Unfortunately, it seems like there's a method wxWindowBase::Move(), and so all my statements of the form list
Henry Swanson
  • 186
  • 13
0
votes
1 answer

Namespaces in Swift

I'm writing an extension to String to return a reversed version of it: extension String{ func rev()->String{ var r = "" r.extend(reverse(self)) return r } } The code works fine, but I'd like to call this method…
cfischer
  • 24,452
  • 37
  • 131
  • 214
0
votes
2 answers

What benefits to var myObj = myObj || { } when myObj already exists?

Been reading Javascript Design Patterns from Addy Osmani, and in the document this simple assignment is used to 'prevent overwriting an already existing object/ namespace': var myNS = myNS || function() {}; So I understand it assigns the same…
webketje
  • 10,376
  • 3
  • 25
  • 54
0
votes
1 answer

column ambiguously defined in oracle

I am no sql expert. I was trying to run following query on my oracle sqlplus prompt select 0 AS initVal, loadTable.amount from accountsTable JOIN loadTable ON num=accNum , loadTable JOIN loanTable ON loadTable.numSeq=loanTable.numSeq and getting…
peeyush
  • 2,841
  • 3
  • 24
  • 43
0
votes
1 answer

Parsing 2 Files Line-By-Line and need to avoid Duplicates (in special cases)

I have 2 files that I'm parsing line-by-line adding the information to 2 separate ArrayList containers. I'm trying to create a final container "finalPNList" that reflects the 'Resulting File/ArrayList' below. Issue is that I'm not…
0
votes
3 answers

Show file path in the tab when there are several files with the same name

Please take a look at the screenshot: As you can see there are 3 tabs with 3 different "index.xml" files opened. I've been looking for an option to show something like "folder/file.extension" in the tabs name to be able to differentiate the files,…
RafaelGP
  • 1,749
  • 6
  • 20
  • 35
0
votes
2 answers

Java override conflict - same name with different return type

I tried to create a class that extended File class (java.io.File) and implement TreeNode interface like below: public class mTreeNode extends File implements TreeNode{} and tried to implement TreeNode methods but a conflict occurred. public String…
Mahyar Ina
  • 29
  • 6
-1
votes
1 answer

design of js library and namespace pollution

i want to create a js library (for helping with tests). i want this library to add one new method X to Array or Object. but some people may not want this behavior and instead would prefer to be able to choose the name (Y instead of X) or even having…
piotrek
  • 13,982
  • 13
  • 79
  • 165
-1
votes
1 answer

Namespace collision with AFNetworking framework constants

If my static library is using AFNetworking and a client project is also using it, it seems like constants defined in AFNetworking will collide, causing the client project not to be able to build (duplicate symbol error). How are things like this…
Boon
  • 40,656
  • 60
  • 209
  • 315
-2
votes
2 answers

VBScript / ASP Classic - Avoiding name conflict with function parameters

I'm working on an old application that often declares variables that seem to be global, using identifiers likely to be used elsewhere. When writing a function, some parameters happen to have the same name as those global variables, and it is hardly…
Virus721
  • 8,061
  • 12
  • 67
  • 123
-2
votes
2 answers

How to solve diamond issue in C++?

I have following test program #include using namespace std; class Faculty { // data members of Faculty public: Faculty(int x) { cout<<"Faculty::Faculty(int ) called"<< endl; } void test() { cout<<"Faculty::test…
BSalunke
  • 11,499
  • 8
  • 34
  • 68
1 2 3 4
5