8

As a programmer I have always assumed that using != as meaning not equal to when writing text (usually on the internet) came from programming languages. Is this true or is the origin different?

  • 5
    Doesn't this belong on programmers.SE more? – svick Apr 23 '11 at 20:27
  • 2
    Well, I bet it could have been posted there. Personally I think english.SE is better since I'm asking about its use in regular text, like when people write stuff like "biking != fun". – Zeta Two Apr 24 '11 at 0:15
  • 2
    A point not mentioned in any answer yet (but which could be added to almost any of them, which is why I'm mentioning it here): some of these languages use ! for NOT already, so != is slightly more natural than <>, or the other ASCII-only operators from the Wikipedia article mentioned in one answer. – Mark Hurd Sep 11 '11 at 7:43
  • en.wikipedia.org/wiki/List_of_mathematical_symbols - list Exclamation mark (or "bang") as negation in Math. – romaninsh Apr 9 '16 at 21:19
12

C and the unix shells use != for not equal, it comes from the maths symbol ≠.

The earlier computer langauge FORTRAN that was (and is) used for more mathematical work uses .ne. because it was invented before the symbols on keyboards were standardised

  • 7
    No, FORTRAN did not use .ne. because of a lack of symbol standardization, but mainly because when the relation operators .EQ., .NE., etc. were added in the forth standard version of the language, the necessary parsing of the = symbol (used for assignment) was already quite complicated, and overloading it for the equals relation was considered undesirable. – mgkrebbs Jul 17 '11 at 20:00
  • 3
    I also disagree with this, on the basis that it has more to do with C's choice to make ! be the boolean negation operator. Other languages existed that used /=, which when juxtaposed look much more like the mathematical symbol . The C designers purposely chose against that. – T.E.D. Nov 2 '11 at 22:01
  • @TED it's also because you need a unary NOT operator and "|" "/" are both already used – mgb Nov 2 '11 at 22:07
  • My college professor claimed that .NE. was carelessly bolted on the the Fortran standard -- so much so, he said, that you can still see the bolts. – Fraser Orr Nov 2 '11 at 23:02
  • 1
    @MartinBeckett - Right. But it is also due to the (formerly) unique features of C that mathematical operators may be combined with the assignment operator to produce a mathematical assignment operator, and that assignment operators return a result. In other words, the more normal /= boolean op was not available in C because it is already being used for something else that could be used in a boolean context. Writing if (x /= 2) works just fine in C, but it returns true every time unless x is 0 (or an integer type of 1). And it has side-effects. Ick. – T.E.D. Nov 3 '11 at 14:17
3

Yes, this is from programming languages such as C and C++.

The symbol used to denote inequation — when items are not equal — is a slashed equals sign "≠" (Unicode 2260).

Most programming languages, limiting themselves to the ASCII character set, use ~=, !=, /=, =/=, or <> to represent their boolean inequality operator.

Source: Wikipedia.


(Edit: Combining vincente and Mark Hurd's comment with something extra.)

!= may have first appeared in the B language, which was a precursor to C. It does not appear in BCPL which was an inspiration for B, so perhaps the B designers were the first.

And some languages (including B and C) use ! for logical negation (aka NOT), so != is slightly more natural than > and the other ASCII-only operators. Again, BCPL is different: it uses ~a to mean "NOT a", but uses a!b for !(a+b).

  • 1
    Anybody know what language uses =/=? It's kinda cute, but I've never seen it before. – T.E.D. Nov 4 '11 at 18:30
  • 2
    @T.E.D. Erlang uses =/= and Prolog uses =\=. – Hugo Nov 8 '11 at 19:39
  • Just for trivia, <> was chosen in some languages because it can be interpreted as "less than or greater than", or in other words, not equal. – devios1 Feb 22 '12 at 22:38
1

Yes, this originated in the C language.

  • 2
    The syntax appears first (that I know of) in the B language that was a precursor to C. It does not appear in BCPL which was an inspiration for B, so perhaps the B designers were the first, – vincente Jul 17 '11 at 18:48
  • Note that the (formerly quite popular) Pascal family of languages tended to use /= instead. != is a quirk of C that became popular mostly because C's syntax became popular. – T.E.D. Nov 2 '11 at 22:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.