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. Interesting boolean technique

Interesting boolean technique

Scheduled Pinned Locked Moved The Weird and The Wonderful
question
13 Posts 11 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.
  • D Dan Neely

    if (e.Message.StartsWith("Case we don't care about"))
    {// easier to read than sticking a ! in the conditional
    }
    else
    {
    errorToDisplay += "\n" + e.Message;
    }

    8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch. :wtf:

    Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

    M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #2

    Dan Neely wrote:

    8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch.

    Well, in Ruby, you could write: unless (e.Message.StartsWith(..... which I find even more baffling linguistically. I always have to mentally change that to "if not..." Or worse (because the conditional comes at the end, and in one case I never saw the conditional because it was off-screen on a very long line), but better linguistically:

    errorToDisplay += "\n" + e.Message unless e.Message.StartsWith("Case we don't care about")

    Why do I bring this up? Because idiomitic Ruby frowns on negative conditions, like "if !". Personally, there is a lot of idiomatic Ruby that I refuse to use because it just seems idiotic, not idiomatic. Marc

    Latest Article - APOD Scraper

    D D L 3 Replies Last reply
    0
    • M Marc Clifton

      Dan Neely wrote:

      8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch.

      Well, in Ruby, you could write: unless (e.Message.StartsWith(..... which I find even more baffling linguistically. I always have to mentally change that to "if not..." Or worse (because the conditional comes at the end, and in one case I never saw the conditional because it was off-screen on a very long line), but better linguistically:

      errorToDisplay += "\n" + e.Message unless e.Message.StartsWith("Case we don't care about")

      Why do I bring this up? Because idiomitic Ruby frowns on negative conditions, like "if !". Personally, there is a lot of idiomatic Ruby that I refuse to use because it just seems idiotic, not idiomatic. Marc

      Latest Article - APOD Scraper

      D Offline
      D Offline
      Dan Neely
      wrote on last edited by
      #3

      I'm glad none of the Ruby on the project I'm working on uses that wtftern... X|

      Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

      1 Reply Last reply
      0
      • M Marc Clifton

        Dan Neely wrote:

        8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch.

        Well, in Ruby, you could write: unless (e.Message.StartsWith(..... which I find even more baffling linguistically. I always have to mentally change that to "if not..." Or worse (because the conditional comes at the end, and in one case I never saw the conditional because it was off-screen on a very long line), but better linguistically:

        errorToDisplay += "\n" + e.Message unless e.Message.StartsWith("Case we don't care about")

        Why do I bring this up? Because idiomitic Ruby frowns on negative conditions, like "if !". Personally, there is a lot of idiomatic Ruby that I refuse to use because it just seems idiotic, not idiomatic. Marc

        Latest Article - APOD Scraper

        D Offline
        D Offline
        DaveAuld
        wrote on last edited by
        #4

        Jade also supports 'unless'. e.g. (example from my article Feeling Jaded with Jade? Don't Be![^])

        - var bob = 'woman'
        unless bob == 'man'
        p Bob is a not man!

        would output <p>Bob is not a man!</p> Couple of times, I have confused myself trying to unwind what I wrote.

        1 Reply Last reply
        0
        • D Dan Neely

          if (e.Message.StartsWith("Case we don't care about"))
          {// easier to read than sticking a ! in the conditional
          }
          else
          {
          errorToDisplay += "\n" + e.Message;
          }

          8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch. :wtf:

          Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

          B Offline
          B Offline
          BillW33
          wrote on last edited by
          #5

          Yes, very clever, but I think sticking a ! in the conditional is easier to follow. ;) :)

          Just because the code works, it doesn't mean that it is good code.

          1 Reply Last reply
          0
          • D Dan Neely

            if (e.Message.StartsWith("Case we don't care about"))
            {// easier to read than sticking a ! in the conditional
            }
            else
            {
            errorToDisplay += "\n" + e.Message;
            }

            8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch. :wtf:

            Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

            D Offline
            D Offline
            Deflinek
            wrote on last edited by
            #6

            Every today's clever code is tomorrow's WTF ;)

            -- "My software never has bugs. It just develops random features."

            1 Reply Last reply
            0
            • D Dan Neely

              if (e.Message.StartsWith("Case we don't care about"))
              {// easier to read than sticking a ! in the conditional
              }
              else
              {
              errorToDisplay += "\n" + e.Message;
              }

              8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch. :wtf:

              Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

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

              I think BASICplus has/had unless (and maybe until), but I doubt it was used much. In my opinion, one of the shortcomings of BASIC, and its progeny, is it's plethora of keywords and built-in functions. C et al do very well with far fewer. Better to learn to do more with less. # define unless(x) if(!(x)) :-D Oh, what did I step in...? I pulled out my BASICplus book. Modified IF : <statement> IF <condition> UNLESS : <statement> UNLESS <condition> Implied FOR Loop : <statement> FOR <variable> = <starting value> TO <ending value> [ STEP <increment> ] FOR ... UNTIL and FOR ... WHILE : FOR <variable> = <starting value> TO <ending value> [ STEP <increment> ] WHILE | UNTIL <condition>

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

              1 Reply Last reply
              0
              • D Dan Neely

                if (e.Message.StartsWith("Case we don't care about"))
                {// easier to read than sticking a ! in the conditional
                }
                else
                {
                errorToDisplay += "\n" + e.Message;
                }

                8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch. :wtf:

                Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                B Offline
                B Offline
                Bernhard Hiller
                wrote on last edited by
                #8

                Well, you could re-factor it to

                if (CaseWeCareAbout(e.Message))
                {
                errorToDisplay += "\n" + e.Message;
                }
                ...
                private bool CaseWeCareAbout(string input)
                {
                bool weDontCare = input. StartsWith("Case we don't care about");
                bool weCare = !weDontCare;
                return weCare;
                }

                Some time later, you'll think: wtf did I need so many lines and an extra function for such a simple task. Every beginner can understand that, but I ought to be capable to understand far more complicated things. What will others think of me writing such code? deflinek's message is quite correct.

                OriginalGriffO 1 Reply Last reply
                0
                • M Marc Clifton

                  Dan Neely wrote:

                  8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch.

                  Well, in Ruby, you could write: unless (e.Message.StartsWith(..... which I find even more baffling linguistically. I always have to mentally change that to "if not..." Or worse (because the conditional comes at the end, and in one case I never saw the conditional because it was off-screen on a very long line), but better linguistically:

                  errorToDisplay += "\n" + e.Message unless e.Message.StartsWith("Case we don't care about")

                  Why do I bring this up? Because idiomitic Ruby frowns on negative conditions, like "if !". Personally, there is a lot of idiomatic Ruby that I refuse to use because it just seems idiotic, not idiomatic. Marc

                  Latest Article - APOD Scraper

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

                  That whole "condition at the end" thing is crazy. It's like "you thought this was crazy and wouldn't work half the time? ha! conditional!" I hate surprises.

                  1 Reply Last reply
                  0
                  • B Bernhard Hiller

                    Well, you could re-factor it to

                    if (CaseWeCareAbout(e.Message))
                    {
                    errorToDisplay += "\n" + e.Message;
                    }
                    ...
                    private bool CaseWeCareAbout(string input)
                    {
                    bool weDontCare = input. StartsWith("Case we don't care about");
                    bool weCare = !weDontCare;
                    return weCare;
                    }

                    Some time later, you'll think: wtf did I need so many lines and an extra function for such a simple task. Every beginner can understand that, but I ought to be capable to understand far more complicated things. What will others think of me writing such code? deflinek's message is quite correct.

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

                    Nah, that still uses "!" which is "hard to read". Try this:

                    private bool CaseWeCareAbout(string input)
                    {
                    bool weDontCare = input. StartsWith("Case we don't care about");
                    bool weCare = weDontCare ? false : true;
                    return weCare;
                    }

                    Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                    "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

                    P 1 Reply Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      Nah, that still uses "!" which is "hard to read". Try this:

                      private bool CaseWeCareAbout(string input)
                      {
                      bool weDontCare = input. StartsWith("Case we don't care about");
                      bool weCare = weDontCare ? false : true;
                      return weCare;
                      }

                      Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                      P Offline
                      P Offline
                      PaulLinton
                      wrote on last edited by
                      #11

                      If ! is hard to read then make it more obvious

                      private bool CaseWeCareAbout(string input)
                      {
                      return !!!!!!!!!!!input.StartsWith("Case we don't care about");
                      }

                      B 1 Reply Last reply
                      0
                      • P PaulLinton

                        If ! is hard to read then make it more obvious

                        private bool CaseWeCareAbout(string input)
                        {
                        return !!!!!!!!!!!input.StartsWith("Case we don't care about");
                        }

                        B Offline
                        B Offline
                        Bernhard Hiller
                        wrote on last edited by
                        #12

                        Of course, a normal exclamation mark ought to be "closed" with an inverted exclamation mark, i.e.

                        return !!!!!!!!!!!input.StartsWith("Case we don't care about")¡¡¡¡¡¡¡¡¡¡¡;

                        1 Reply Last reply
                        0
                        • D Dan Neely

                          if (e.Message.StartsWith("Case we don't care about"))
                          {// easier to read than sticking a ! in the conditional
                          }
                          else
                          {
                          errorToDisplay += "\n" + e.Message;
                          }

                          8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch. :wtf:

                          Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                          S Offline
                          S Offline
                          Super Lloyd
                          wrote on last edited by
                          #13

                          If you find it nice! The compiler understood either way, so do human! ;P

                          My programming get away... The Blog... DirectX for WinRT/C# since 2013! Taking over the world since 1371!

                          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