Results 1 to 20 of 20
Thread: Abbreviated Arithmetic
 10102010, 09:08 AM #1Member
 Join Date
 Oct 2010
 Posts
 13
 Rep Power
 0
Abbreviated Arithmetic
Hello,
I'm very new to Java, and I'm actually taking an intro course so hopefully my questions isn't silly. :) One of the questions we are asked is why is abbreviated arithmetic important to java and how it's used effectively. I've done several google searches to research this but haven't come up with anything. Can someone explain it to me or give me some good resources to read about it, please?
 10102010, 01:37 PM #2abbreviated arithmetic
How does that relate to the arithmetic operators: +*/%
 10102010, 08:55 PM #3Member
 Join Date
 Oct 2010
 Posts
 13
 Rep Power
 0
Well, from our notes, they discuss two types of abbreviated arithmetic within two categories of augments  increments and decrements.
So it looks like it is talking about things like c+=a; instead of c = c + a; or ++c; instead of c = c+1;
Honestly, when I reviewed the notes, I was actually wondering why we use the abbreviations like this and what makes using these easier than writing c = c + a;
Any help would be very much appreciated. Thanks for responding so fast!
 10102010, 09:00 PM #4why is abbreviated arithmetic important to java
The prefix and postfix notations are useful, but again can be confusing.
 10102010, 09:07 PM #5Member
 Join Date
 Oct 2010
 Posts
 13
 Rep Power
 0
It's more of a discussion question that I have to answer. I've tried googling it with different wording, but it doesn't seem like there is anything discussing what makes abbreviated arithemetic important.

Many feel that abbreviated arithmetic is little more than syntactic sugar, and per Alan Perlis, "syntactic sugar causes cancer of the semicolon".
 10102010, 09:34 PM #7

 10102010, 10:16 PM #9
 10102010, 10:22 PM #10Member
 Join Date
 Oct 2010
 Posts
 13
 Rep Power
 0
LOL. So what you all are saying is that abbreviated arithemetic really isn't all that important?
Oh this will totally make the discussion question harder to answer. I'll have to look up syntactic sugar and read about that one. LOL
 10112010, 04:09 AM #11Member
 Join Date
 Aug 2010
 Posts
 16
 Rep Power
 0
Don't forget c *= 2 amd c /= 2 :D.
I love increments, it makes for loops easier to write....
 10112010, 07:11 AM #12
You missed c &= 2; c = 2; and c ^= 2;
Hmm, are there any more?
db
 10112010, 08:06 PM #13
All that remains is the remainder: %=.
So we have a list then: ++ (pre/post),  (pre/post), +=, =, *=, /=, &=, =, ^=, %=.
 10112010, 08:12 PM #14
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,651
 Blog Entries
 7
 Rep Power
 21
Part of the 'fun' is that the left hand operand isn't evaluated and not prone to widening conversions; let b be of type byte and do this: 'b+= 3' versus 'b= b+3'. In e.g. C more fun can be shown ;)
kind regards,
Jos
 10112010, 08:13 PM #15
In those cases (which are rarer than just a basic "int x = 5; x += 2;" type thing), the programmer should make it explicit which types are being used and how they're being added. ;)
 10112010, 08:29 PM #16
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,651
 Blog Entries
 7
 Rep Power
 21
 10112010, 08:31 PM #17
I totally agree that abbreviated arithmetic should be used (only 'cause I'm lazy but that's beside the point); however when conversions are involved in a convoluted way (such as with bytes and ints being mixed), there should be some kind of explicit conversion rather than just hoping that it converts correctly.
 10122010, 11:27 AM #18
If I had to write an answer to this question, I'd probably just say that abbreviated arithmetic eliminates redundancy in the code.
Sincerely, Joshua Green
Please REP if I help :)
 10122010, 10:52 PM #19Member
 Join Date
 Oct 2010
 Posts
 13
 Rep Power
 0
Thanks for all the responses. You guys are awesome!
 10132010, 12:46 AM #20Member
 Join Date
 Aug 2010
 Posts
 16
 Rep Power
 0
Similar Threads

Character arithmetic issues
By mljrg in forum Advanced JavaReplies: 1Last Post: 08042010, 12:52 PM 
Polynomial Arithmetic Java
By thisisIT in forum New To JavaReplies: 3Last Post: 03092010, 05:33 PM 
Polynomials Arithmetic
By thisisIT in forum New To JavaReplies: 3Last Post: 03092010, 01:27 PM 
Char as an arithmetic operator
By gatzke in forum New To JavaReplies: 2Last Post: 01272009, 04:21 PM 
Arithmetic Stacks
By unc123w in forum New To JavaReplies: 22Last Post: 10212008, 08:24 PM
Bookmarks