Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!think!mit-eddie!genrad!decvax!decwrl!sun!rmarti From: rmarti@sun.UUCP Newsgroups: net.lang.c Subject: Re: Precedent for use of = Message-ID: <4824@sun.uucp> Date: Mon, 7-Jul-86 13:44:55 EDT Article-I.D.: sun.4824 Posted: Mon Jul 7 13:44:55 1986 Date-Received: Tue, 8-Jul-86 06:46:13 EDT References: <1954@brl-smoke.ARPA> Organization: Sun Microsystems, Inc. Lines: 43 > Everybody keeps guessing at the reasons for the use of = for asignment > and == for equality tests. How about a different angle: how many times > in a program do you assign something versus how many times you compare things? > > [ ... ] > > Maybe Mssrs. Kernighan and/or Ritchie would like to give some input on > their reasons of choice. > ------- They already did. Let me quote K&R, p.17: The double equals sign == is the C notation for "is equal to" (like Fortrans's .EQ.). This symbol is used to distinguish the equality test from the single = used for assignment. Since assignment is about twice as frequent as equality testing in typical C programs, it's appropriate that the operator be half as long. Personally, I still prefer := for assignment and = for equality over = and ==. I also think that the keystroke argument is ridiculous (flames to /dev/null). The problem with = and == is further aggravated by the fact that in C an assignment is an expression and not a statement, so that code like if (i = 0) { /* do something */ } else { /* do something else */ } is legal C and usually /* does something else */ than you expected :-) Despite that, I would never call Messrs K&R idiots, as Niklaus Wirth has been labeled in a recent message (not the one I am responding to): I think both C and Pascal have been reasonable designs of programming languages and important contributions to the computing community. -- Robert Marti, Sun Microsystems, Inc. UUCP: ...{cbosgd,decvax,decwrl,hplabs,ihnp4,pyramid,seismo,ucbvax}!sun!rmarti ARPA: rmarti@sun.com