C obscenities = versus :=

One of the worst mistakes ever made (in my humble opinion) by the designers of C was that related to the use of = to signify assignment. The choice of = as an assignment operator harks back to Fortran, where it was deemed a good idea to be copied by hoards of language designers since. In early Fortran it *may* have made sense, considering that equality was designated using the term .EQ., although in later years (F95), this too devolved to the ubiquitous == inaugurated in C. The problem lies with the fact that mathematics uses the = operator to denote a comparison for equality. The use of = in Fortran essentially forced the equality operation, A = B, the left operand is made to equal the expression which exists in the right operand. It was Algol which surprisingly led the surge to look for an alternative, using := instead.

None of this would be an issue, if C didn’t allow code like this:

if (something = 0)
    something = something + 1;

But it does. There is nothing seemingly wrong about this except that the value of the variable something will always be set to 0, regardless of what its value was before the if statement. That’s because when it evaluated the expression in the if statement, it sets something to 0, and because the value 0 is false, it skips the inner workings of the if statement. It does not check to see if something is zero.

There of course was a simpler solution. Programming has been around for over 60 years, why not (and I know this is radical) include two new symbols: ← to denote assignment (thereby stopping anybody from writing a+b =c), and ≠ for inequality. Then = could be used for its original intended purpose. Oh, and while we’re at it let’s include ≤ and ≥. Wrapped in the mists of time there is a language called APL which used such syntax.

I mean it’s not rocket science. More functionality can be added to existing keys on the keyboard, and keys like _, and ~ could be moved, replaced by ←, and ≠.


One thought on “C obscenities = versus :=

  1. Tim says:

    “forced equality”
    You’d think that because of the anti-communist political climate, someone at the time might have spotted the philosophical inconsistency.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.