{{Short description|Method of distinguishing elements with the same identifier in computing}} {{other uses|Constant fraction discriminator|Foster–Seeley discriminator}}

In computing, a '''discriminator''' is a field of characters designed to separate a certain element from others of the same identifier. As an example, suppose that a program must save two unique objects to memory, both of whose identifiers happen to be {{code|foo}}. To ensure the two objects are not conflated, the program may assign ''discriminators'' to the objects in the form of numbers; thus, {{code|foo (1)}} and {{code|foo (2)}} distinguish both objects named {{code|foo}}.

This has been adopted by programming languages as well as digital platforms for instant messaging and massively multiplayer online games.

== In instant messaging == A discriminator is used to disambiguate a user from other users who wish to identify under the same username.

=== Discord === On Discord, a discriminator used to be a four-digit suffix added to the end of a username. This allowed for up to 10000 user accounts to take the same name.

==== Transition away from discriminators ==== In 2023, co-founder Stanislav Vishnevskiy wrote on a company blog post about the technical debt caused by the discriminator system, stating that the system resulted in nearly half of the company's friend requests failing to connect. The platform implemented discriminators in the early days of the service, he wrote. When the platform was initially introduced, the software developers' priority was to let its users take any username they want without receiving a “your desired username is taken” error. Discord had no friend system at first, thus letting people take names in different letter cases, making usernames case-sensitive.<ref name="mehrotra-2023-05">{{Cite web |url= https://screenrant.com/discord-new-username-change-discriminators-tag-update/ |title= Discord's New Usernames: Everything You Need To Know About The Update |last= Mehrotra |first= Shikhar |date= May 7, 2023 |access-date= June 12, 2023 |work= Screen Rant }}</ref>

Discord also introduced a global display name system, wherein a user may input a default nickname to be shown on top of the messages they sent in lieu of their platform-wide username, Vishnevskiy touted on Reddit.<ref name="shakir-2023-05">{{Cite news |url= https://www.theverge.com/2023/5/6/23711332/discord-username-changes-community-backlash-handles |title= Discord's username change is causing discord |last= Shakir |first= Umar |date= May 6, 2023 |access-date= June 12, 2023 |work= The Verge |publisher= Vox Media }}</ref>

The platform created a transition process to a system of pseudonyms wherein all new usernames would be case-insensitive lowercase and limited to the ASCII characters of A–Z, 0–9, the full stop and the underscore. The transition would happen over the course of months, with the accounts that were registered the oldest, and paid subscribers, receiving the opportunity to reserve their name earlier.

This change was criticized online for being a step backward, as users could be a risk of being impersonated. A notable indie game studio noted that it could no longer claim its own name on the platform.<ref>{{Cite news |url= https://www.gamespot.com/articles/discords-controversial-new-policy-has-prevented-a-dev-from-claiming-its-own-name/1100-6514438/ |title= Discord's Controversial New Policy Has Prevented A Dev From Claiming Its Own Name |last= Wright |first= Steven |date= May 22, 2023 |access-date= June 12, 2023 |publisher= Fandom, Inc. |work= GameSpot }}</ref> Discord pointed to its processes for users with high visibility and longstanding business relationships with the company for reserving a username under the new system. The old discriminator-oriented system also mitigated the rush to get unique usernames for sale on the black market, leading to swatting and online harassment.<ref>{{Cite news |url= https://www.bbc.com/news/technology-65483184 |title= Discord plans to make everyone change their username |date= May 4, 2023 |access-date= June 12, 2023 |work= BBC News |publisher= British Broadcasting Company |last= Gerken |first= Tom }}</ref><ref name="shakir-2023-05" />

== In digital distribution == Battle.net implements a suffix of four-digit numbers to its usernames.

== In computer data storage == {{technical|date=October 2011|section}} === Common Object Request Broker Architecture === A discriminator is a typed tag field present in the Common Object Request Broker Architecture, the interface description language of the Object Management Group. It exists as type and value definitions of tagged unions that determine which union member is selected in the current union instance. This is done by introduction of the classic C switch construct as part of the classic C union.<ref>{{Cite web |url= http://www.omg.org/technology/documents/formal/corba_iiop.htm |archive-url=https://web.archive.org/web/20071015141909/http://www.omg.org/technology/documents/formal/corba_iiop.htm |archive-date=October 15, 2007 |date=March 12, 2004 |title= CORBA/IIOP Specification 3.0.3 |author= Object Management Group |work= OMG.org }}</ref><ref>{{Cite web |url= http://www.omg.org/cgi-bin/doc?formal/02-06-07 |title= CORBA 3.0 - IDL Syntax and Semantics chapter |date= March 12, 2004 |work= OMG.org }}</ref> Unlike in some conventional programming languages offering support for unions, the discriminator in IDL is not identical to the selected field name. Here is an example of an IDL union type definition:

<syntaxhighlight lang="c"> union Register switch (char) { case 'a': case 'b': short AX;

case 'c': long EAX;

default: octet AL; }; </syntaxhighlight>

The effective value of the ''Register'' type may contain AX as the selected field, but the discriminator value may be either 'a' or 'b' and is stored in memory separately. Therefore, IDL logically separates information about the currently selected field name and the union effective value from information about the current discriminator value. In the example above, the discriminator value may be any of the following: 'a', 'b', 'c', as well as all other characters belonging to the IDL <code>char</code> type, since the <code>default</code> branch specified in the example ''Register'' type allows the use of the remaining characters as well.

=== Other interface definition languages === The Microsoft Interface Definition Language also supports tagged unions, allowing to choose the discriminator via an attribute in an enclosing structure or function.<ref>{{Cite web |url= https://msdn.microsoft.com/en-us/library/aa367275(VS.85).aspx |title= Microsoft discriminator attribute documentation |work= Microsoft Learn |date= October 25, 2019 }}</ref>

== In deserialization == When deserializing data from a data serialization format such as JSON in a object-oriented language, a type discriminator may be used for polymorphic deserialization.

In this example the discriminator field is named "$type".

A serialization of a book. <syntaxhighlight lang="json"> { "$type": "book", "title": "Do Androids Dream of Electric Sheep?", "author": "Philip K. Dick" } </syntaxhighlight>

A serialization of a movie. <syntaxhighlight lang="json"> { "$type": "movie", "title": "Titanic", "director": "James Cameron" } </syntaxhighlight>

Both data serializations share a common field here named "$type" which serves as the type discriminator. The book have the book-specific field "author", while the movie have the movie-specific field "director".

This facilitates the deserialization of data to different classes depending on the value of the type discriminator.

== Alternatives == A friend code is a unique twelve-digit number that could be exchanged with friends and be used to maintain individual friend lists in each video game. Friend codes were generated from an identifier unique to a copy of a game and the universally unique identifier corresponding to that of a user's device.<ref>{{Cite news |url= https://www.msn.com/en-us/entertainment/gaming/how-to-add-friends-on-nintendo-switch-in-5-easy-steps-with-photos/ar-AA1a2FaN |title= How to Add Friends on Nintendo Switch: In 5 Easy Steps With Photos |last= Studdard |first= Kim |date= April 19, 2023 |via= MSN |access-date= June 12, 2023 }}</ref>

==References== {{reflist}}

Category:Programming language topics

{{prog-lang-stub}}