shortcutting in boolean expressions?

This is a discussion on shortcutting in boolean expressions? within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by cyberfish because a() and b() have side effects. That could be considered a problem by itself. But ...

  1. #16
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Quote Originally Posted by cyberfish View Post
    because a() and b() have side effects.
    That could be considered a problem by itself. But it depends on the exact situation.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #17
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    That could be considered a problem by itself. But it depends on the exact situation.
    hmm, I wasn't aware of that. Mind explaining it a bit?
    Thanks

  3. #18
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Well, if the primary use of the functions is their side effect, and the return value is merely a success indicator, it's mostly fine. (I'd prefer exceptions, but not everyone does, and in some environment, exceptions cannot be used.)

    If the return value is more significant and the side effect is really a side effect, that's bad.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Novice needs help
    By ghaasemi in forum C++ Programming
    Replies: 9
    Last Post: 05-30-2009, 09:20 AM
  2. Regular expressions [Boost]
    By Desolation in forum C++ Programming
    Replies: 8
    Last Post: 12-30-2006, 10:10 PM
  3. Liitle help with boolean expressions
    By Voyd in forum C++ Programming
    Replies: 2
    Last Post: 05-30-2006, 09:17 PM
  4. Casting boolean as string
    By doofusboy in forum C Programming
    Replies: 11
    Last Post: 11-10-2005, 12:24 PM
  5. Use struct to create a boolean type
    By skyglin in forum C Programming
    Replies: 6
    Last Post: 06-18-2003, 09:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21