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. true-false or false-true

true-false or false-true

Scheduled Pinned Locked Moved The Lounge
comquestion
33 Posts 23 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.
  • M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #1

    Which do you prefer: Option 1:

    Assert.IsTrue(token != Guid.Empty, "Token not received.");

    or Option 2:

    Assert.IsFalse(token == Guid.Empty, "Token not received.");

    Personally, I go for option 1, because there's a bias to assert that things are true rather than false (except in politics) and it reads better. I have to process the false == into a true !=. With Option 1, I don't have to do that. Interesting how the mind works. Maybe a psychopath would go for option 2? ;P

    Latest Articles:
    Microservices: Myth, Madness, or Magic I Take Exception

    G F L R K 16 Replies Last reply
    0
    • M Marc Clifton

      Which do you prefer: Option 1:

      Assert.IsTrue(token != Guid.Empty, "Token not received.");

      or Option 2:

      Assert.IsFalse(token == Guid.Empty, "Token not received.");

      Personally, I go for option 1, because there's a bias to assert that things are true rather than false (except in politics) and it reads better. I have to process the false == into a true !=. With Option 1, I don't have to do that. Interesting how the mind works. Maybe a psychopath would go for option 2? ;P

      Latest Articles:
      Microservices: Myth, Madness, or Magic I Take Exception

      G Offline
      G Offline
      GKP1992
      wrote on last edited by
      #2

      I'd go for first as well, coz it's more straightforward. Less mental operations = better readability. Unless you're writing negative tests of course 😆 Edit :- okay, you're saying the same thing. So I agree.

      1 Reply Last reply
      0
      • M Marc Clifton

        Which do you prefer: Option 1:

        Assert.IsTrue(token != Guid.Empty, "Token not received.");

        or Option 2:

        Assert.IsFalse(token == Guid.Empty, "Token not received.");

        Personally, I go for option 1, because there's a bias to assert that things are true rather than false (except in politics) and it reads better. I have to process the false == into a true !=. With Option 1, I don't have to do that. Interesting how the mind works. Maybe a psychopath would go for option 2? ;P

        Latest Articles:
        Microservices: Myth, Madness, or Magic I Take Exception

        F Offline
        F Offline
        Forogar
        wrote on last edited by
        #3

        I always have a tendency to put positives first, eg.

        if (thing == true)
        {
        // do ok thing.
        }
        else
        {
        // error message
        }

        ...so, obviously, I would go for "Assert.isTrue".

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

        G 1 Reply Last reply
        0
        • M Marc Clifton

          Which do you prefer: Option 1:

          Assert.IsTrue(token != Guid.Empty, "Token not received.");

          or Option 2:

          Assert.IsFalse(token == Guid.Empty, "Token not received.");

          Personally, I go for option 1, because there's a bias to assert that things are true rather than false (except in politics) and it reads better. I have to process the false == into a true !=. With Option 1, I don't have to do that. Interesting how the mind works. Maybe a psychopath would go for option 2? ;P

          Latest Articles:
          Microservices: Myth, Madness, or Magic I Take Exception

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

          Always Option 1. Thislike I can focus on "!=" or "==" for the complete information.

          It does not solve my Problem, but it answers my question

          1 Reply Last reply
          0
          • M Marc Clifton

            Which do you prefer: Option 1:

            Assert.IsTrue(token != Guid.Empty, "Token not received.");

            or Option 2:

            Assert.IsFalse(token == Guid.Empty, "Token not received.");

            Personally, I go for option 1, because there's a bias to assert that things are true rather than false (except in politics) and it reads better. I have to process the false == into a true !=. With Option 1, I don't have to do that. Interesting how the mind works. Maybe a psychopath would go for option 2? ;P

            Latest Articles:
            Microservices: Myth, Madness, or Magic I Take Exception

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

            I also prefer #1.  But shouldn't it be "Token received" if token isn't Guid.Empty? :) /ravi

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

            Richard DeemingR 1 Reply Last reply
            0
            • M Marc Clifton

              Which do you prefer: Option 1:

              Assert.IsTrue(token != Guid.Empty, "Token not received.");

              or Option 2:

              Assert.IsFalse(token == Guid.Empty, "Token not received.");

              Personally, I go for option 1, because there's a bias to assert that things are true rather than false (except in politics) and it reads better. I have to process the false == into a true !=. With Option 1, I don't have to do that. Interesting how the mind works. Maybe a psychopath would go for option 2? ;P

              Latest Articles:
              Microservices: Myth, Madness, or Magic I Take Exception

              K Offline
              K Offline
              KarstenK
              wrote on last edited by
              #6

              I understand Option 1 easier and faster Thats my style :cool:

              Press F1 for help or google it. Greetings from Germany

              1 Reply Last reply
              0
              • F Forogar

                I always have a tendency to put positives first, eg.

                if (thing == true)
                {
                // do ok thing.
                }
                else
                {
                // error message
                }

                ...so, obviously, I would go for "Assert.isTrue".

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

                G Offline
                G Offline
                GKP1992
                wrote on last edited by
                #7

                In most cases I put the conditions which prevent code execution (like error cases) first and the condition in which the code must execute comes last.

                OriginalGriffO 1 Reply Last reply
                0
                • R Ravi Bhavnani

                  I also prefer #1.  But shouldn't it be "Token received" if token isn't Guid.Empty? :) /ravi

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

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

                  Ravi Bhavnani wrote:

                  But shouldn't it be "Token received" if token isn't Guid.Empty?

                  A perfect illustration of the mental gymnastics involved here. :) Assert.IsTrue displays the message if the assumption isn't met. Assert.IsTrue(token != Guid.Empty, ... displays the message if token == Guid.Empty, meaning that "token not received" is the correct message.


                  "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

                  R B 2 Replies Last reply
                  0
                  • G GKP1992

                    In most cases I put the conditions which prevent code execution (like error cases) first and the condition in which the code must execute comes last.

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #9

                    I do the same - if only because the "failure case code" is generally shorter:

                    MessageBox.Show("...", "...");
                    return;

                    And it's more obvious what is going on that way. Plus ... it's a layer less indentation:

                    if (goodThing)
                    {
                    ...
                    }
                    else
                    {
                    MessageBox.Show("...", "...");
                    return;
                    }

                    Vs:

                    if (!goodThing)
                    {
                    MessageBox.Show("...", "...");
                    return;
                    }
                    ...

                    And it groups validations at the top of methods, leaving the "good code" alone at the end:

                    if (!goodThing)
                    {
                    MessageBox.Show("...", "...");
                    return;
                    }
                    if (!otherThingIWantToSee)
                    {
                    MessageBox.Show("...", "...");
                    return;
                    }
                    ...

                    Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    R G 2 Replies Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      I do the same - if only because the "failure case code" is generally shorter:

                      MessageBox.Show("...", "...");
                      return;

                      And it's more obvious what is going on that way. Plus ... it's a layer less indentation:

                      if (goodThing)
                      {
                      ...
                      }
                      else
                      {
                      MessageBox.Show("...", "...");
                      return;
                      }

                      Vs:

                      if (!goodThing)
                      {
                      MessageBox.Show("...", "...");
                      return;
                      }
                      ...

                      And it groups validations at the top of methods, leaving the "good code" alone at the end:

                      if (!goodThing)
                      {
                      MessageBox.Show("...", "...");
                      return;
                      }
                      if (!otherThingIWantToSee)
                      {
                      MessageBox.Show("...", "...");
                      return;
                      }
                      ...

                      Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                      R Offline
                      R Offline
                      Rick York
                      wrote on last edited by
                      #10

                      I once had to adhere to a rather arcane coding standard that required only one return statement per function. It made for some very deep indentation so I resorted to using many more very small functions. It's a bit less of an issue now with very high resolution monitors but back then it was very annoying.

                      "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

                      M 1 Reply Last reply
                      0
                      • OriginalGriffO OriginalGriff

                        I do the same - if only because the "failure case code" is generally shorter:

                        MessageBox.Show("...", "...");
                        return;

                        And it's more obvious what is going on that way. Plus ... it's a layer less indentation:

                        if (goodThing)
                        {
                        ...
                        }
                        else
                        {
                        MessageBox.Show("...", "...");
                        return;
                        }

                        Vs:

                        if (!goodThing)
                        {
                        MessageBox.Show("...", "...");
                        return;
                        }
                        ...

                        And it groups validations at the top of methods, leaving the "good code" alone at the end:

                        if (!goodThing)
                        {
                        MessageBox.Show("...", "...");
                        return;
                        }
                        if (!otherThingIWantToSee)
                        {
                        MessageBox.Show("...", "...");
                        return;
                        }
                        ...

                        Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                        G Offline
                        G Offline
                        GKP1992
                        wrote on last edited by
                        #11

                        Now that you wrote it, I see why it is obvious. I didn't think about it that much when I posted. To me it just made better sense when coding probably because of the lesser/better indentation. Also it really pays off when the code is called recursively.

                        1 Reply Last reply
                        0
                        • M Marc Clifton

                          Which do you prefer: Option 1:

                          Assert.IsTrue(token != Guid.Empty, "Token not received.");

                          or Option 2:

                          Assert.IsFalse(token == Guid.Empty, "Token not received.");

                          Personally, I go for option 1, because there's a bias to assert that things are true rather than false (except in politics) and it reads better. I have to process the false == into a true !=. With Option 1, I don't have to do that. Interesting how the mind works. Maybe a psychopath would go for option 2? ;P

                          Latest Articles:
                          Microservices: Myth, Madness, or Magic I Take Exception

                          T Offline
                          T Offline
                          TheGreatAndPowerfulOz
                          wrote on last edited by
                          #12

                          One

                          #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                          1 Reply Last reply
                          0
                          • M Marc Clifton

                            Which do you prefer: Option 1:

                            Assert.IsTrue(token != Guid.Empty, "Token not received.");

                            or Option 2:

                            Assert.IsFalse(token == Guid.Empty, "Token not received.");

                            Personally, I go for option 1, because there's a bias to assert that things are true rather than false (except in politics) and it reads better. I have to process the false == into a true !=. With Option 1, I don't have to do that. Interesting how the mind works. Maybe a psychopath would go for option 2? ;P

                            Latest Articles:
                            Microservices: Myth, Madness, or Magic I Take Exception

                            M Offline
                            M Offline
                            Mark_Wallace
                            wrote on last edited by
                            #13

                            Always go for what is, not what is not, if possible. Less mental boggling, that way.

                            I wanna be a eunuchs developer! Pass me a bread knife!

                            1 Reply Last reply
                            0
                            • Richard DeemingR Richard Deeming

                              Ravi Bhavnani wrote:

                              But shouldn't it be "Token received" if token isn't Guid.Empty?

                              A perfect illustration of the mental gymnastics involved here. :) Assert.IsTrue displays the message if the assumption isn't met. Assert.IsTrue(token != Guid.Empty, ... displays the message if token == Guid.Empty, meaning that "token not received" is the correct message.


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

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

                              Gaaah! :-O I'm going to blame it on lack of caffeine, even though the real reason is sheer stupidity. /ravi

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

                              1 Reply Last reply
                              0
                              • R Rick York

                                I once had to adhere to a rather arcane coding standard that required only one return statement per function. It made for some very deep indentation so I resorted to using many more very small functions. It's a bit less of an issue now with very high resolution monitors but back then it was very annoying.

                                "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

                                M Offline
                                M Offline
                                Mycroft Holmes
                                wrote on last edited by
                                #15

                                An adamant refusal to use GOTO :laugh:

                                Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

                                R G 2 Replies Last reply
                                0
                                • M Marc Clifton

                                  Which do you prefer: Option 1:

                                  Assert.IsTrue(token != Guid.Empty, "Token not received.");

                                  or Option 2:

                                  Assert.IsFalse(token == Guid.Empty, "Token not received.");

                                  Personally, I go for option 1, because there's a bias to assert that things are true rather than false (except in politics) and it reads better. I have to process the false == into a true !=. With Option 1, I don't have to do that. Interesting how the mind works. Maybe a psychopath would go for option 2? ;P

                                  Latest Articles:
                                  Microservices: Myth, Madness, or Magic I Take Exception

                                  C Offline
                                  C Offline
                                  Chris Maunder
                                  wrote on last edited by
                                  #16

                                  I always prefer a positive comparison rather than negative so I prefer the first. Except the "IsFalse" kinda does my head in. How about

                                  Assert.IsNotTrue(token == Guid.Empty, "Token not received.");

                                  *head explodes*

                                  cheers Chris Maunder

                                  1 Reply Last reply
                                  0
                                  • M Mycroft Holmes

                                    An adamant refusal to use GOTO :laugh:

                                    Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

                                    R Offline
                                    R Offline
                                    Rick York
                                    wrote on last edited by
                                    #17

                                    Using goto was forbidden. It was in C++ so that had something to do with it. The irony of it was they had this arcane and tedious coding standard and used a library they wrote themselves that was utterly atrocious. It is easily the worst library I have ever had to deal with. Here's one little tidbit : the whole thing was built around a state machine that changed states by throwing an exception. :wtf: I would have to work really hard to come up with a design worse than that.

                                    "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

                                    N 1 Reply Last reply
                                    0
                                    • M Marc Clifton

                                      Which do you prefer: Option 1:

                                      Assert.IsTrue(token != Guid.Empty, "Token not received.");

                                      or Option 2:

                                      Assert.IsFalse(token == Guid.Empty, "Token not received.");

                                      Personally, I go for option 1, because there's a bias to assert that things are true rather than false (except in politics) and it reads better. I have to process the false == into a true !=. With Option 1, I don't have to do that. Interesting how the mind works. Maybe a psychopath would go for option 2? ;P

                                      Latest Articles:
                                      Microservices: Myth, Madness, or Magic I Take Exception

                                      Sander RosselS Offline
                                      Sander RosselS Offline
                                      Sander Rossel
                                      wrote on last edited by
                                      #18

                                      Just thinking outside of the box here...

                                      Assert.NotEqual(token, Guid.Empty, "Token not received");

                                      :D

                                      Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                                      1 Reply Last reply
                                      0
                                      • Richard DeemingR Richard Deeming

                                        Ravi Bhavnani wrote:

                                        But shouldn't it be "Token received" if token isn't Guid.Empty?

                                        A perfect illustration of the mental gymnastics involved here. :) Assert.IsTrue displays the message if the assumption isn't met. Assert.IsTrue(token != Guid.Empty, ... displays the message if token == Guid.Empty, meaning that "token not received" is the correct message.


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

                                        B Offline
                                        B Offline
                                        BillWoodruff
                                        wrote on last edited by
                                        #19

                                        Richard Deeming wrote:

                                        perfect illustration of the mental gymnastic

                                        Or, perfect illustration of the twisted minds that defined 'Assert semantics :wtf:

                                        «Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

                                        1 Reply Last reply
                                        0
                                        • M Marc Clifton

                                          Which do you prefer: Option 1:

                                          Assert.IsTrue(token != Guid.Empty, "Token not received.");

                                          or Option 2:

                                          Assert.IsFalse(token == Guid.Empty, "Token not received.");

                                          Personally, I go for option 1, because there's a bias to assert that things are true rather than false (except in politics) and it reads better. I have to process the false == into a true !=. With Option 1, I don't have to do that. Interesting how the mind works. Maybe a psychopath would go for option 2? ;P

                                          Latest Articles:
                                          Microservices: Myth, Madness, or Magic I Take Exception

                                          S Offline
                                          S Offline
                                          Stuart Dootson
                                          wrote on last edited by
                                          #20

                                          I prefer the second... I often find myself doing (in C++ unit tests) ```C++ ASSERT(!some_condition); ``` or ```C++ ASSERT(some_condition == false); ``` rather than ```C++ ASSERT_FALSE(some_condition); ``` Same thing, really, but as you say, there's an unconscious desire to be positive, I guess.

                                          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                                          K 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