Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Not really a horror, but useless all the same

Not really a horror, but useless all the same

Scheduled Pinned Locked Moved The Weird and The Wonderful
comgame-devquestion
8 Posts 7 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anthony Mushrow
    wrote on last edited by
    #1

    Came across this just the other day: bool value = (someObject == NULL)? true : false; The same thing is dotted around in a few places, some of the the other way around (returning false if the statement is true). I just can't understand why anybody would bother.

    My current favourite word is: Delicious!

    -SK Genius

    Game Programming articles start -here[^]-

    L M M 3 Replies Last reply
    0
    • A Anthony Mushrow

      Came across this just the other day: bool value = (someObject == NULL)? true : false; The same thing is dotted around in a few places, some of the the other way around (returning false if the statement is true). I just can't understand why anybody would bother.

      My current favourite word is: Delicious!

      -SK Genius

      Game Programming articles start -here[^]-

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      SK Genius wrote:

      I just can't understand why anybody would bother.

      What on earth is wrong with a ternary operation[^]? There are valid reasons for using it. It is a hint to the compiler that the software engineer wants to make an assignment with no conditional branching if possible. The compiler will try to perform an optimization such as ternary operator optimization[^] if it is possible. I guess he could have written it like this and it would possibly optimized the same:

      bool value;
      if(NULL == someObject)
      value = true;
      else
      value = false;

      But who really cares? They are equally readable to me although I prefer the ternary operation. :) Best Wishes, -David Delaune

      D P 2 Replies Last reply
      0
      • L Lost User

        SK Genius wrote:

        I just can't understand why anybody would bother.

        What on earth is wrong with a ternary operation[^]? There are valid reasons for using it. It is a hint to the compiler that the software engineer wants to make an assignment with no conditional branching if possible. The compiler will try to perform an optimization such as ternary operator optimization[^] if it is possible. I guess he could have written it like this and it would possibly optimized the same:

        bool value;
        if(NULL == someObject)
        value = true;
        else
        value = false;

        But who really cares? They are equally readable to me although I prefer the ternary operation. :) Best Wishes, -David Delaune

        D Offline
        D Offline
        DePatrick
        wrote on last edited by
        #3

        Nothing wrong with ternary operation really. But wouldn't

        (NULL == someObject)

        returns True/False that can be assigned straight to "value"?

        L 1 Reply Last reply
        0
        • D DePatrick

          Nothing wrong with ternary operation really. But wouldn't

          (NULL == someObject)

          returns True/False that can be assigned straight to "value"?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          DePatrick wrote:

          returns True/False that can be assigned straight to "value"?

          Yep, that is true. Best Wishes, -David Delaune

          L 1 Reply Last reply
          0
          • L Lost User

            SK Genius wrote:

            I just can't understand why anybody would bother.

            What on earth is wrong with a ternary operation[^]? There are valid reasons for using it. It is a hint to the compiler that the software engineer wants to make an assignment with no conditional branching if possible. The compiler will try to perform an optimization such as ternary operator optimization[^] if it is possible. I guess he could have written it like this and it would possibly optimized the same:

            bool value;
            if(NULL == someObject)
            value = true;
            else
            value = false;

            But who really cares? They are equally readable to me although I prefer the ternary operation. :) Best Wishes, -David Delaune

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            But it's not necessary in this case.

            1 Reply Last reply
            0
            • L Lost User

              DePatrick wrote:

              returns True/False that can be assigned straight to "value"?

              Yep, that is true. Best Wishes, -David Delaune

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Randor wrote:

              that is true

              I second that; it is absolutely (true==!false)==true?true:!false :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


              1 Reply Last reply
              0
              • A Anthony Mushrow

                Came across this just the other day: bool value = (someObject == NULL)? true : false; The same thing is dotted around in a few places, some of the the other way around (returning false if the statement is true). I just can't understand why anybody would bother.

                My current favourite word is: Delicious!

                -SK Genius

                Game Programming articles start -here[^]-

                M Offline
                M Offline
                Michael Bergman
                wrote on last edited by
                #7

                It is probably a misunderstanding of the form: BOOL value = (someObject == NULL) ? TRUE : FALSE; where #define FALSE 0 #define TRUE !(FALSE)

                m.bergman

                -- For Bruce Schneier, quanta only have one state : afraid.

                1 Reply Last reply
                0
                • A Anthony Mushrow

                  Came across this just the other day: bool value = (someObject == NULL)? true : false; The same thing is dotted around in a few places, some of the the other way around (returning false if the statement is true). I just can't understand why anybody would bother.

                  My current favourite word is: Delicious!

                  -SK Genius

                  Game Programming articles start -here[^]-

                  M Offline
                  M Offline
                  Megidolaon
                  wrote on last edited by
                  #8

                  I don't see the horror...

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups