Skip to content

The Comparison Operator Dilemma #2

@LadyBeGood

Description

@LadyBeGood

When comparing x and y, there are three posibilities

  • x < y
  • x = y
  • x > y

What if you want to find the "opposite" of each of these operations?

Then there are 2 ways to express "inverse" of these primary operations:

1. Negation

Defining in terms of negation.

  • !(x < y)
  • !(x = y)
  • !(x > y)

2. Relational Complement

Defining in terms of what is true instead.

  • x = y || x > y
  • x < y || x > y
  • x < y || x = y

Most programming languages provide shortcut operators for these inverse operations.

Going by the first philosophy, we have:

  • x !< y
  • x != y
  • x !> y

Going by the second philosophy, we have:

  • x >= y
  • x <> y
  • x <= y

The dilemma, as someone who is designing a language wanting both symmetry and practicality, is which one of these should be chosen?

Most C-like languages use a mixture instead, breaking symmetry in favour of practicality:

  • x >= y
  • x != y
  • x <= y

I don't know man, I was indecisive for a long time. For now I just decided to not add these "inverse" operators in the language.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions