Results 1 to 20 of 20
Thread: Abbreviated Arithmetic
- 10-10-2010, 09:08 AM #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?
- 10-10-2010, 01:37 PM #2
Can you define your term please?abbreviated arithmetic
How does that relate to the arithmetic operators: +-*/%
- 10-10-2010, 08:55 PM #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!
- 10-10-2010, 09:00 PM #4
If this is an opinion survey, then I don't think c +=a is very important. It can lead to confusion when reading code.why is abbreviated arithmetic important to java
The prefix and postfix notations are useful, but again can be confusing.
- 10-10-2010, 09:07 PM #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.
-
Many feel that abbreviated arithmetic is little more than syntactic sugar, and per Alan Perlis, "syntactic sugar causes cancer of the semicolon".
- 10-10-2010, 09:34 PM #7
-
- 10-10-2010, 10:16 PM #9
- 10-10-2010, 10:22 PM #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
- 10-11-2010, 04:09 AM #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....
- 10-11-2010, 07:11 AM #12
You missed c &= 2; c |= 2; and c ^= 2;
Hmm, are there any more?
db
- 10-11-2010, 08:06 PM #13
All that remains is the remainder: %=.
So we have a list then: ++ (pre/post), -- (pre/post), +=, -=, *=, /=, &=, |=, ^=, %=.
- 10-11-2010, 08:12 PM #14
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
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
- 10-11-2010, 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. ;)
- 10-11-2010, 08:29 PM #16
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
- 10-11-2010, 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.
- 10-12-2010, 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 :)
- 10-12-2010, 10:52 PM #19
Member
- Join Date
- Oct 2010
- Posts
- 13
- Rep Power
- 0
Thanks for all the responses. You guys are awesome!
- 10-13-2010, 12:46 AM #20
Member
- Join Date
- Aug 2010
- Posts
- 16
- Rep Power
- 0
Similar Threads
-
Character arithmetic issues
By mljrg in forum Advanced JavaReplies: 1Last Post: 08-04-2010, 12:52 PM -
Polynomial Arithmetic Java
By thisisIT in forum New To JavaReplies: 3Last Post: 03-09-2010, 05:33 PM -
Polynomials Arithmetic
By thisisIT in forum New To JavaReplies: 3Last Post: 03-09-2010, 01:27 PM -
Char as an arithmetic operator
By gatzke in forum New To JavaReplies: 2Last Post: 01-27-2009, 04:21 PM -
Arithmetic Stacks
By unc123w in forum New To JavaReplies: 22Last Post: 10-21-2008, 08:24 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks