Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.help Subject: Re: [OT] Re: Why would one use += 1 at the place of ++? Date: Thu, 19 May 2011 22:57:45 -0400 Organization: A noiseless patient Spider Lines: 58 Message-ID: References: <8762p7upgn.fsf@merciadriluca-station.MERCIADRILUCA> <4t6Bp.534$pi2.511@newsfe11.iad> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 20 May 2011 02:58:18 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="BrOwaJANne849xlH+KPYjQ"; logging-data="6580"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BQV+VimgipyH6OZBrqyu8" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 In-Reply-To: Cancel-Lock: sha1:N559EaW/eEu4Xa3TUDWXAMLcjzI= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:704 On 5/19/2011 10:35 AM, Patricia Shanahan wrote: > On 5/19/2011 5:03 AM, Eric Sosman wrote: >> On 5/19/2011 6:40 AM, David Lamb wrote: >>> [...] >>> I think ++ exists only because the hardware on which C was developed had >>> an addressing mode that did it atomically in the very special case of >>> referring to >>> something = array[index++]; >> >> FWIW, some guy named Dennis Ritchie says this is not true. >> >> "People often guess that [++ and --]were created to use the >> auto-increment and auto-decrement address modes provided >> by the DEC PDP-11 on which C and Unix first became popular. >> This is historically impossible, since there was no PDP-11 >> when B was developed." >> >> "B" is the language from which C inherited ++ and --, and much else. >> > > There seem to me to be two reasons for the ++ and -- operators in C. > Typing was slow and inconvenient when C was invented, so there was a > motivation to make code terse. C made extensive use of macros that could > represent expressions but not statements, so much was done as side effects. C's macros have always been able to expand to arbitrary sequences of valid source tokens. They can generate expressions, parts of expressions, statements, parts of statements, blocks, parts of blocks, complete functions, and complete suites of functions. The only thing they can't generate is preprocessor statements. Wisdom, bitter experience, and the KISS principle operate to keep macros safely caged. But they thump against the bars and rattle the doors, and are always a threat to escape and run riot. > I do not understand why those operators exist in Java. They cannot be > used without going against style advice in the JLS and Java is not a > terse language. Not sure what style advice you refer to; the word "style" doesn't appear in the JLS' index. As for using the operators, I personally think they're convenient and easy to read in some contexts where the spelled-out counterparts would look clunky, mostly when I'm sliding through an array advancing an index as I go: `x[i++]' would be clumsy to rewrite with `+='. Java inherits a lot from C. I've always supposed (no evidence) that it was a deliberate choice, intended to make it easier for C and C++ programmers to learn Java. And that (I suppose) is why Java has C's infelicitous precedence for | and & w.r.t. almost everything else. However, the boneheaded precedence of instanceof w.r.t. ! is Java's own fault, and can't be blamed on "It's our faulty parentage." (Personal opinion, not advanced as fact.) -- Eric Sosman esosman@ieee-dot-org.invalid