ArticleslgStudy

science

Discriminator

Discriminator is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Discriminator rather than just read about it. In short: 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 foo.

Key takeaways

  • Discriminator belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Discriminator to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Discriminator from memory before moving on to harder problems.

Reference excerpt

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 foo. To ensure the two objects are not conflated, the program may assign discriminators to the objects in the form of numbers; thus, foo (1) and foo (2) distinguish both objects named 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. 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. 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. 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.

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

In computer data storage

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. 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:

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 char type, since the default 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.

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.

A serialization of a movie.

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.

References

Worked examples

Example 1 — a first encounter with Discriminator

Start with the simplest possible case. Write down what Discriminator claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Discriminator before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Discriminator ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Discriminator

In research
Discriminator appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Discriminator in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Discriminator is common in secondary-school and first-year university syllabi. It links to neighbouring topics Programming language topic stubs, Programming language topics, so understanding it makes those chapters shorter.
In everyday life
Look for Discriminator outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Discriminator” →

How to study Discriminator in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Discriminator means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Discriminator out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Discriminator in simple terms?

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 foo.

Why does Discriminator matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Discriminator?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Discriminator.

Tags

  • Programming language topic stubs
  • Programming language topics

Keep exploring