# Thread: Abbreviated Arithmetic

1. Member
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?

2. abbreviated arithmetic
Can you define your term please?
How does that relate to the arithmetic operators: +-*/%

3. Member
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!

4. why is abbreviated arithmetic important to java
If this is an opinion survey, then I don't think c +=a is very important. It can lead to confusion when reading code.
The prefix and postfix notations are useful, but again can be confusing.

5. Member
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.

6. Many feel that abbreviated arithmetic is little more than syntactic sugar, and per Alan Perlis, "syntactic sugar causes cancer of the semicolon".

7. Originally Posted by Fubarable
...and per Alan Perlis, "syntactic sugar causes cancer of the semicolon".
I'm going to go and cry myself to sleep now. Thanks, Alan Perlis.

8. Originally Posted by Zack
I'm going to go and cry myself to sleep now. Thanks, Alan Perlis.
There's no need to worry, no need to cry, and in fact you're in luck:

I know how to do a semicolonoscopy.

I am deeply sorry for any groans and indigestion that this pitiful pun has caused.

9. Originally Posted by Fubarable
I am deeply sorry for any groans and indigestion that this pitiful pun has caused.
I'll get you for this. I will. :rolleyes:

10. Member
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

11. Member
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....

12. You missed c &= 2; c |= 2; and c ^= 2;

Hmm, are there any more?

db

13. All that remains is the remainder: %=.

So we have a list then: ++ (pre/post), -- (pre/post), +=, -=, *=, /=, &=, |=, ^=, %=.

14. 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

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. ;)

16. Originally Posted by Zack
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. ;)
There's more between heaven and earth than just basic arithmetic; that's 'abreviated arithmetic'. It is a well defined language feature, whether you like it or not so why not use it?

kind regards,

Jos

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.

18. If I had to write an answer to this question, I'd probably just say that abbreviated arithmetic eliminates redundancy in the code.

19. Member
Join Date
Oct 2010
Posts
13
Rep Power
0
Thanks for all the responses. You guys are awesome!

20. Member
Join Date
Aug 2010
Posts
16
Rep Power
0
I always chuckle when I see c++, c = c + 1, therefore 0 = 1... I know, I am mentally impaired

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•