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. The Lounge
  3. PQOTD

PQOTD

Scheduled Pinned Locked Moved The Lounge
csharpquestion
59 Posts 31 Posters 0 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.
  • F Forogar

    Nah! As long as it compiles...

    - I would love to change the world, but they won’t give me the source code.

    Kornfeld Eliyahu PeterK Offline
    Kornfeld Eliyahu PeterK Offline
    Kornfeld Eliyahu Peter
    wrote on last edited by
    #33

    Yeah! It compiles. After then you can rub your head to find where the bug is!

    I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

    "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

    J 1 Reply Last reply
    0
    • M Marc Clifton

      Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?

      		bool more = ProcessFlyouts();
      		more = more || ProcessCarrierAnimations();
      

      How would you change it to "do the right thing?" Marc

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #34

      How about:

      more &= ProcessCarrierAnimations();

      The difficult we do right away... ...the impossible takes slightly longer.

      1 Reply Last reply
      0
      • M Marc Clifton

        Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?

        		bool more = ProcessFlyouts();
        		more = more || ProcessCarrierAnimations();
        

        How would you change it to "do the right thing?" Marc

        J Offline
        J Offline
        Jorgen Andersson
        wrote on last edited by
        #35

        Is it just me that would have done it as a oneliner?

        Wrong is evil and must be defeated. - Jeff Ello[^]

        P 1 Reply Last reply
        0
        • J Jorgen Andersson

          Is it just me that would have done it as a oneliner?

          Wrong is evil and must be defeated. - Jeff Ello[^]

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

          That could make setting a breakpoint on the second call difficult. :shrug:

          You'll never get very far if all you do is follow instructions.

          J 1 Reply Last reply
          0
          • P PIEBALDconsult

            That could make setting a breakpoint on the second call difficult. :shrug:

            You'll never get very far if all you do is follow instructions.

            J Offline
            J Offline
            Jorgen Andersson
            wrote on last edited by
            #37

            No big deal to change if necessary. :shrug: But I actually find it easier to read on one line.

            Wrong is evil and must be defeated. - Jeff Ello[^]

            1 Reply Last reply
            0
            • M Marc Clifton

              Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?

              		bool more = ProcessFlyouts();
              		more = more || ProcessCarrierAnimations();
              

              How would you change it to "do the right thing?" Marc

              E Offline
              E Offline
              Ennis Ray Lynch Jr
              wrote on last edited by
              #38

              -|

              Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost "All users always want Excel" --Ennis Lynch

              1 Reply Last reply
              0
              • M Marc Clifton

                Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?

                		bool more = ProcessFlyouts();
                		more = more || ProcessCarrierAnimations();
                

                How would you change it to "do the right thing?" Marc

                R Offline
                R Offline
                Ravi Bhavnani
                wrote on last edited by
                #39

                There's a risk that ProcessCarrierAnimations() may never be invoked, so the right thing (IMHO) would be to do something like this:

                bool processFlyouts = ProcessFlyouts();
                bool processCarrierAnimations = ProcessCarrierAnimations();
                bool more = processFlyouts || processCarrierAnimations;

                /ravi

                My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                1 Reply Last reply
                0
                • M Marc Clifton

                  Kornfeld Eliyahu Peter wrote:

                  you have to switch the order

                  Yes indeed. Or use the bitwise operator. Marc

                  D Offline
                  D Offline
                  dan sh
                  wrote on last edited by
                  #40

                  Marc Clifton wrote:

                  bitwise operator

                  So boolean is foolish?

                  My CP workspace: Incredibly trivial and probably useless code samples[^]

                  1 Reply Last reply
                  0
                  • M Marc Clifton

                    Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?

                    		bool more = ProcessFlyouts();
                    		more = more || ProcessCarrierAnimations();
                    

                    How would you change it to "do the right thing?" Marc

                    D Offline
                    D Offline
                    dan sh
                    wrote on last edited by
                    #41

                    No it did not do anything unexpected. || operator uses short-circuit evaluation. I would assume the intent was to call ProcessCarrierAnimations only if more was false.

                    My CP workspace: Incredibly trivial and probably useless code samples[^]

                    1 Reply Last reply
                    0
                    • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

                      Yeah! It compiles. After then you can rub your head to find where the bug is!

                      I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

                      J Offline
                      J Offline
                      JimmyRopes
                      wrote on last edited by
                      #42

                      Kornfeld Eliyahu Peter wrote:

                      It compiles. After then you someone else will can rub your their head to find where the bug is!

                      FTFY :-D

                      The report of my death was an exaggeration - Mark Twain
                      Simply Elegant Designs JimmyRopes Designs
                      I'm on-line therefore I am. JimmyRopes

                      1 Reply Last reply
                      0
                      • M Marc Clifton

                        Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?

                        		bool more = ProcessFlyouts();
                        		more = more || ProcessCarrierAnimations();
                        

                        How would you change it to "do the right thing?" Marc

                        C Offline
                        C Offline
                        Chris Quinn
                        wrote on last edited by
                        #43

                        It compiled?

                        ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

                        1 Reply Last reply
                        0
                        • P PIEBALDconsult

                          I never follow other peoples' rules. :cool:

                          You'll never get very far if all you do is follow instructions.

                          S Offline
                          S Offline
                          SortaCore
                          wrote on last edited by
                          #44

                          It's my rule that people have to breathe (or die trying).

                          1 Reply Last reply
                          0
                          • M Marc Clifton

                            Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?

                            		bool more = ProcessFlyouts();
                            		more = more || ProcessCarrierAnimations();
                            

                            How would you change it to "do the right thing?" Marc

                            A Offline
                            A Offline
                            Adam Tibi
                            wrote on last edited by
                            #45

                            This is JavaScript style, the developer meant, if "more" is "undefined" then try the other option ProcessCarrierAnimations(). But obviously, this doesn't work in C#.

                            Make it simple, as simple as possible, but not simpler.

                            1 Reply Last reply
                            0
                            • M Marc Clifton

                              Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?

                              		bool more = ProcessFlyouts();
                              		more = more || ProcessCarrierAnimations();
                              

                              How would you change it to "do the right thing?" Marc

                              G Offline
                              G Offline
                              Gary Wheeler
                              wrote on last edited by
                              #46

                              Just to be contrary:

                              bool more = false;
                              if (ProcessFlyouts()) more = true;
                              if (ProcessCarrierAnimations()) more = true;

                              Software Zen: delete this;

                              1 Reply Last reply
                              0
                              • N Nish Nishant

                                |

                                Regards, Nish


                                Blog: voidnish.wordpress.com Latest article: C++ 11 features in Visual C++ 2013 Preview

                                G Offline
                                G Offline
                                Gary Wheeler
                                wrote on last edited by
                                #47

                                Yuck. One of my least favorite things when reading someone else's C/C++ code is when they mix logical and bit-wise operators in an expression. In this case, using a bit-wise operator on bool values just seems wrong.

                                Software Zen: delete this;

                                N 1 Reply Last reply
                                0
                                • G Gary Wheeler

                                  Yuck. One of my least favorite things when reading someone else's C/C++ code is when they mix logical and bit-wise operators in an expression. In this case, using a bit-wise operator on bool values just seems wrong.

                                  Software Zen: delete this;

                                  N Offline
                                  N Offline
                                  Nish Nishant
                                  wrote on last edited by
                                  #48

                                  I agree, it's not something I'd use myself. I was only answering Marc's academic question :-)

                                  Regards, Nish


                                  Blog: voidnish.wordpress.com Latest article: C++ 11 features in Visual C++ 2013 Preview

                                  G 1 Reply Last reply
                                  0
                                  • N Nish Nishant

                                    I agree, it's not something I'd use myself. I was only answering Marc's academic question :-)

                                    Regards, Nish


                                    Blog: voidnish.wordpress.com Latest article: C++ 11 features in Visual C++ 2013 Preview

                                    G Offline
                                    G Offline
                                    Gary Wheeler
                                    wrote on last edited by
                                    #49

                                    I thought that was the case - your response just seemed rather unNish-like :laugh:.

                                    Software Zen: delete this;

                                    N 1 Reply Last reply
                                    0
                                    • G Gary Wheeler

                                      I thought that was the case - your response just seemed rather unNish-like :laugh:.

                                      Software Zen: delete this;

                                      N Offline
                                      N Offline
                                      Nish Nishant
                                      wrote on last edited by
                                      #50

                                      Heh :-)

                                      Regards, Nish


                                      Blog: voidnish.wordpress.com Latest article: C++ 11 features in Visual C++ 2013 Preview

                                      1 Reply Last reply
                                      0
                                      • B BobJanova

                                        It will run either ProcessFlyouts, or ProcessCarrierAnimations, or neither, and the variable will tell you if it successfully ran either. I would imagine you either want && or |.

                                        J Offline
                                        J Offline
                                        James Curran
                                        wrote on last edited by
                                        #51

                                        >> It will run either ProcessFlyouts, or ProcessCarrierAnimations, or neither, Um... Not even close. It will, unquestionably, run ProcessFlyouts. It may also run ProcessCarrierAnimations.

                                        Truth, James

                                        B 1 Reply Last reply
                                        0
                                        • M Marc Clifton

                                          Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?

                                          		bool more = ProcessFlyouts();
                                          		more = more || ProcessCarrierAnimations();
                                          

                                          How would you change it to "do the right thing?" Marc

                                          J Offline
                                          J Offline
                                          James Curran
                                          wrote on last edited by
                                          #52

                                          The "early out" semantics of the logical operators (|| and &&) are the same for C#, C++, Java, and C, and have been well-specified since the First Edition of K&R C. How could the result possibly be unexpected?

                                          Truth, James

                                          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