Results 1 to 20 of 20
  1. #1
    SweetLD215 is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Exclamation 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. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

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

  3. #3
    SweetLD215 is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    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. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    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. #5
    SweetLD215 is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    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. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

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

  7. #7
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    Quote Originally Posted by Fubarable View Post
    ...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. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Zack View Post
    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. #9
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    Quote Originally Posted by Fubarable View Post
    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. #10
    SweetLD215 is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    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. #11
    Join Date
    Aug 2010
    Posts
    16
    Rep Power
    0

    Default

    Don't forget c *= 2 amd c /= 2 :D.

    I love increments, it makes for loops easier to write....

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default

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

    Hmm, are there any more?

    db

  13. #13
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    All that remains is the remainder: %=.

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

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,784
    Blog Entries
    7
    Rep Power
    21

    Default

    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. #15
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    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. #16
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,784
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Zack View Post
    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. #17
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    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. #18
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

    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 :)

  19. #19
    SweetLD215 is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    Thanks for all the responses. You guys are awesome!

  20. #20
    Join Date
    Aug 2010
    Posts
    16
    Rep Power
    0

    Default

    I always chuckle when I see c++, c = c + 1, therefore 0 = 1... I know, I am mentally impaired

Similar Threads

  1. Character arithmetic issues
    By mljrg in forum Advanced Java
    Replies: 1
    Last Post: 08-04-2010, 01:52 PM
  2. Polynomial Arithmetic Java
    By thisisIT in forum New To Java
    Replies: 3
    Last Post: 03-09-2010, 06:33 PM
  3. Polynomials Arithmetic
    By thisisIT in forum New To Java
    Replies: 3
    Last Post: 03-09-2010, 02:27 PM
  4. Char as an arithmetic operator
    By gatzke in forum New To Java
    Replies: 2
    Last Post: 01-27-2009, 05:21 PM
  5. Arithmetic Stacks
    By unc123w in forum New To Java
    Replies: 22
    Last Post: 10-21-2008, 09:24 PM

Posting Permissions

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