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. Lets make sure, shall we

Lets make sure, shall we

Scheduled Pinned Locked Moved The Weird and The Wonderful
rubyquestion
7 Posts 6 Posters 1 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.
  • K Offline
    K Offline
    k5054
    wrote on last edited by
    #1

    Doing some code clean up and found this gem

    if ( flag && test_fn() )
    {
    if ( test_fn() )
    {
    /* do domething */
    }
    }

    test_fn() isn't particularly expensive ... but really?

    Richard DeemingR L M N 4 Replies Last reply
    0
    • K k5054

      Doing some code clean up and found this gem

      if ( flag && test_fn() )
      {
      if ( test_fn() )
      {
      /* do domething */
      }
      }

      test_fn() isn't particularly expensive ... but really?

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      So presumably test_fn looks something like this:

      private int _testCallCount = 0;

      public bool test_fn()
      {
      _testCallCount++;
      return (_testCallCount & 1) == 0;
      }

      :)


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      • K k5054

        Doing some code clean up and found this gem

        if ( flag && test_fn() )
        {
        if ( test_fn() )
        {
        /* do domething */
        }
        }

        test_fn() isn't particularly expensive ... but really?

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

        At least it is not

        if ( ((flag == true) && (test_fn() == true)) == true)
        {
        if ( test_fn()== true )
        {
        /* do domething if it is that much true*/
        }
        }

        :laugh:

        1 Reply Last reply
        0
        • K k5054

          Doing some code clean up and found this gem

          if ( flag && test_fn() )
          {
          if ( test_fn() )
          {
          /* do domething */
          }
          }

          test_fn() isn't particularly expensive ... but really?

          M Offline
          M Offline
          MacSpudster
          wrote on last edited by
          #4

          What if test_fn() does change a global such that, when the next time it runs, may not return true? That makes perfect sense to call a function after already calling validating it. I've set a flag that, when true, also calls a function within an If statement. I once-again call the function to see if we're still good to go, especially in a parallel processing app that can change datapoints before another process gets to it. I then recursion into the function during the function to ensure that no externals have changed while it is in process, for it calls additional functions. And, if you believe I do all this, then hire me at $1 million a year and I'll gladly implement this into yer project!

          X 1 Reply Last reply
          0
          • M MacSpudster

            What if test_fn() does change a global such that, when the next time it runs, may not return true? That makes perfect sense to call a function after already calling validating it. I've set a flag that, when true, also calls a function within an If statement. I once-again call the function to see if we're still good to go, especially in a parallel processing app that can change datapoints before another process gets to it. I then recursion into the function during the function to ensure that no externals have changed while it is in process, for it calls additional functions. And, if you believe I do all this, then hire me at $1 million a year and I'll gladly implement this into yer project!

            X Offline
            X Offline
            Xmen Real
            wrote on last edited by
            #5

            MacSpudster wrote:

            I once-again call the function to see if we're still good to go

            You really should be using locking :P

            TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

            ----------------------------------------------- 128 bit encrypted signature, crack if you can

            L 1 Reply Last reply
            0
            • X Xmen Real

              MacSpudster wrote:

              I once-again call the function to see if we're still good to go

              You really should be using locking :P

              TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

              ----------------------------------------------- 128 bit encrypted signature, crack if you can

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

              I totally agree :thumbsup:

              1 Reply Last reply
              0
              • K k5054

                Doing some code clean up and found this gem

                if ( flag && test_fn() )
                {
                if ( test_fn() )
                {
                /* do domething */
                }
                }

                test_fn() isn't particularly expensive ... but really?

                N Offline
                N Offline
                Nguyen H H Dang
                wrote on last edited by
                #7

                May be this poor guy think that check test_fn() 1 time is not True enough, and he do it twice just for sure :-\

                In code we trust !

                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