Results 1 to 3 of 3
  1. #1
    MGT Madness is offline Member
    Join Date
    Oct 2013
    Rep Power

    Default Should i check before changing?

    Should i do this?
    Java Code:
    if (walking)
    walking = false;

    Or just this?
    Java Code:
    walking = false;
    Which is best to use and why?

    - Thank you for your time :)

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: Should i check before changing?

    I feel tempted to go for the second alternative; it even gives the reader to think about something.

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Rep Power

    Default Re: Should i check before changing?

    I'm on the fence. If you want to do nothing more than toggle the boolean than the second works just fine. But I have to consider future expansions of the code: the first case I read as "When you are walking, the following is a sequence of statements that need to be executed". Right now there is only one, I am guessing there are going to be more.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Changing the Value of a map
    By Whisperer in forum New To Java
    Replies: 4
    Last Post: 10-05-2011, 02:31 PM
  2. Changing 8 to eight...need help!
    By adjit in forum New To Java
    Replies: 31
    Last Post: 06-18-2011, 09:47 PM
  3. Replies: 5
    Last Post: 05-26-2011, 06:55 AM
  4. Replies: 0
    Last Post: 08-14-2010, 10:09 AM

Posting Permissions

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