Seemingly useless code

Sharky Forums


Results 1 to 3 of 3

Thread: Seemingly useless code

  1. #1
    Hammerhead Shark
    Join Date
    Feb 2001
    Posts
    1,612

    Seemingly useless code

    is there EVER any point to code like this:

    Code:
    if (x != y)
        x = y;
    Maybe to avoid dirtying the cache, or something like this?

  2. #2
    NullPointerException rock's Avatar
    Join Date
    Sep 2000
    Location
    York, PA
    Posts
    6,203
    I don't see a point to that code at all. If x is already equal to y, you skip the assignment. If it's not equal to y, it will be afterwards. So why test? Just assign the value and move on.

    Maybe somebody can make an argument that a boolean test exectues faster than an assignment, but this is as case where code readability would trump the microsecond that might be saved.

    Open Source is free like a puppy is free.

    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.

    Understanding Evolution

  3. #3
    Hammerhead Shark SprySpectre's Avatar
    Join Date
    Apr 2004
    Location
    audio nirvana...
    Posts
    1,251
    Useless. Probably does execute faster the times that x==y, but honestly how much difference could that possibly make?
    Audio Setups:
    E-MU 0404 ---toslink---> Panasonic SA-XR55s ---> Ascend Acoustics CBM170's with Dayton 12"
    E-MU 0404 ---analog---> Little Dot II tube amp ---> Beyerdynamics DT880 or Sennheiser HD280 pros.
    Technics SL-1200 MKII ---> TCC TC-750LC Phono Preamp ---> Panasonic SA-XR55s ---> Ascend Acoustics CBM170's with Dayton 12"


    Proud Sharky Folding@Home member! (Rank 37 and counting...)

Posting Permissions

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