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?
-
5Doesn't this belong on programmers.SE more?– svickApr 23, 2011 at 20:27
-
3Well, 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 TwoApr 24, 2011 at 0:15
-
2A 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 HurdSep 11, 2011 at 7:43
-
en.wikipedia.org/wiki/List_of_mathematical_symbols - list Exclamation mark (or "bang") as negation in Math.– romaninshApr 9, 2016 at 21:19
3 Answers
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
-
8No, 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.– mgkrebbsJul 17, 2011 at 20:00
-
3I 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, 2011 at 22:01 -
@TED it's also because you need a unary NOT operator and "|" "/" are both already used– mgbNov 2, 2011 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. Nov 2, 2011 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. Writingif (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, 2011 at 14:17
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).
Yes, this originated in the C language.
-
2The 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,– vincenteJul 17, 2011 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, 2011 at 22:04 -
1@T.E.D. AFAIK Pascal has always used
<>
for inequality. In my Delphi 7 compiler (based firmly on Pascal), I get an error message when trying to compileif 1 /= 2 then
, namely[Error] Unit2.pas(29): Expression expected but '=' found
Jun 25, 2021 at 15:04 -
@ReversedEngineer - Yeah, you're right. Decade younger me was wrong. It was ALGOL68 that used /=. Many of the languages influenced by ALGOL borrowed it, but it looks like C and Pascal prominently did not.– T.E.D.Jun 25, 2021 at 16:32