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. new bool()

new bool()

Scheduled Pinned Locked Moved The Weird and The Wonderful
pythoncomlearning
26 Posts 15 Posters 3 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 Dave Kreskowiak

    Please, for the love of bacon, STOP POSTING THIS CRAP! :-D

    A guide to posting questions on CodeProject

    Click this: Asking questions is a skill. Seriously, do it.
    Dave Kreskowiak

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

    Dave Kreskowiak wrote:

    Please, for the love of bacon, STOP POSTING THIS CRAP!

    :laugh: It's about the only way that I can stay sane. Thank goodness I have TW&TW as an outlet for my pain. Marc

    V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

    D 1 Reply Last reply
    0
    • M Marc Clifton

      Dave Kreskowiak wrote:

      Please, for the love of bacon, STOP POSTING THIS CRAP!

      :laugh: It's about the only way that I can stay sane. Thank goodness I have TW&TW as an outlet for my pain. Marc

      V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #5

      Marc Clifton wrote:

      It's about the only way that I can stay sane.

      Cheech and Chong may have something to help with that. Wait a minute. For some reason I can hear Tommy Chong's voice when I read that code. Sounds about right.

      A guide to posting questions on CodeProject

      Click this: Asking questions is a skill. Seriously, do it.
      Dave Kreskowiak

      1 Reply Last reply
      0
      • D David ONeil

        Too bad he/she(it?) didn't have "bar" in the initial quotes. Then you could have replaced the construct with

        bool isProgrammerCompleteFnIdiot(true);

        Sudden Sun Death Syndrome (SSDS) is a very real concern which we should be raising awareness of. 156 billion suns die every year before they're just 1 billion years old. While the military are doing their part, it simply isn't enough to make the amount of nukes needed to save those poor stars. - TWI2T3D (Reddit)

        Z Offline
        Z Offline
        ZurdoDev
        wrote on last edited by
        #6

        David O'Neil wrote:

        bool isProgrammerCompleteFnIdiot(true) || isProgrammerNew()

        FTFY

        There are two kinds of people in the world: those who can extrapolate from incomplete data. There are only 10 types of people in the world, those who understand binary and those who don't.

        T 1 Reply Last reply
        0
        • Z ZurdoDev

          David O'Neil wrote:

          bool isProgrammerCompleteFnIdiot(true) || isProgrammerNew()

          FTFY

          There are two kinds of people in the world: those who can extrapolate from incomplete data. There are only 10 types of people in the world, those who understand binary and those who don't.

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

          Syntax error: expecting '{' after ')'

          #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

          Z 1 Reply Last reply
          0
          • T TheGreatAndPowerfulOz

            Syntax error: expecting '{' after ')'

            #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

            Z Offline
            Z Offline
            ZurdoDev
            wrote on last edited by
            #8

            Please post your question in Quick Answers.

            There are two kinds of people in the world: those who can extrapolate from incomplete data. There are only 10 types of people in the world, those who understand binary and those who don't.

            1 Reply Last reply
            0
            • M Marc Clifton

              bool isOffset = new bool();
              if (reader["foo"].ToString().ToUpper().Trim() == "BAR")
              isOffset = true;
              else
              isOffset = false;

              I'll stop now. Marc

              V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

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

              Just in case your bools give you a NullReferenceException. And your BaR s have trailing spaces and lower cases. And you really need those if else statements... Just out of curiosity, are you sure Trim() also trims uppercased spaces? :D

              Best, Sander arrgh.js - Bringing LINQ to JavaScript SQL Server for C# Developers Succinctly Object-Oriented Programming in C# Succinctly

              L 1 Reply Last reply
              0
              • Sander RosselS Sander Rossel

                Just in case your bools give you a NullReferenceException. And your BaR s have trailing spaces and lower cases. And you really need those if else statements... Just out of curiosity, are you sure Trim() also trims uppercased spaces? :D

                Best, Sander arrgh.js - Bringing LINQ to JavaScript SQL Server for C# Developers Succinctly Object-Oriented Programming in C# Succinctly

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

                You joke, but I've seen code that "uppercased" spaces to \0

                J 1 Reply Last reply
                0
                • M Marc Clifton

                  bool isOffset = new bool();
                  if (reader["foo"].ToString().ToUpper().Trim() == "BAR")
                  isOffset = true;
                  else
                  isOffset = false;

                  I'll stop now. Marc

                  V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                  J Offline
                  J Offline
                  Jon McKee
                  wrote on last edited by
                  #11

                  A little pointless but not too crazy. bool is just an alias for System.Boolean. The else was the silly part.

                  Boolean isOffset = new Boolean(); //default false
                  if (reader["foo"].ToString().ToUpper().Trim() == "BAR")
                  isOffset = Boolean.Parse(Boolean.TrueString);

                  Though I suspect unlike above that true and false are probably aliases for pre-defined constants. Couldn't find documentation on how they're created; above was just a guess using public Boolean members. Also true and false are operators that can be overloaded to create nullable types prior to .NET 2.0 (Nullable). Of course it's still silly to do it this way. bool is shorter to write and using true and false is both clearer and shorter.

                  L M 3 Replies Last reply
                  0
                  • L Lost User

                    You joke, but I've seen code that "uppercased" spaces to \0

                    J Offline
                    J Offline
                    Jon McKee
                    wrote on last edited by
                    #12

                    That is legitimately frightening :wtf:

                    1 Reply Last reply
                    0
                    • J Jon McKee

                      A little pointless but not too crazy. bool is just an alias for System.Boolean. The else was the silly part.

                      Boolean isOffset = new Boolean(); //default false
                      if (reader["foo"].ToString().ToUpper().Trim() == "BAR")
                      isOffset = Boolean.Parse(Boolean.TrueString);

                      Though I suspect unlike above that true and false are probably aliases for pre-defined constants. Couldn't find documentation on how they're created; above was just a guess using public Boolean members. Also true and false are operators that can be overloaded to create nullable types prior to .NET 2.0 (Nullable). Of course it's still silly to do it this way. bool is shorter to write and using true and false is both clearer and shorter.

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

                      This goes well with a comment such as // deep copy of true

                      1 Reply Last reply
                      0
                      • J Jon McKee

                        A little pointless but not too crazy. bool is just an alias for System.Boolean. The else was the silly part.

                        Boolean isOffset = new Boolean(); //default false
                        if (reader["foo"].ToString().ToUpper().Trim() == "BAR")
                        isOffset = Boolean.Parse(Boolean.TrueString);

                        Though I suspect unlike above that true and false are probably aliases for pre-defined constants. Couldn't find documentation on how they're created; above was just a guess using public Boolean members. Also true and false are operators that can be overloaded to create nullable types prior to .NET 2.0 (Nullable). Of course it's still silly to do it this way. bool is shorter to write and using true and false is both clearer and shorter.

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

                        Well, the whole thing could be reduced to

                        bool isOffset = reader["foo"].ToString().ToUpper().Trim() == "BAR";

                        Why couldn't the programmer see that? Why didn't someone in the 2+ years that this code has been in production fix it? Marc

                        V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

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

                          Well, the whole thing could be reduced to

                          bool isOffset = reader["foo"].ToString().ToUpper().Trim() == "BAR";

                          Why couldn't the programmer see that? Why didn't someone in the 2+ years that this code has been in production fix it? Marc

                          V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                          J Offline
                          J Offline
                          Jon McKee
                          wrote on last edited by
                          #15

                          Very true! :thumbsup: I was just pointing out that new bool() isn't as crazy as it looks at first glance :)

                          M 1 Reply Last reply
                          0
                          • J Jon McKee

                            Very true! :thumbsup: I was just pointing out that new bool() isn't as crazy as it looks at first glance :)

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

                            Jon McKee wrote:

                            I was just pointing out that new bool() isn't as crazy as it looks at first glance

                            Quite so. I don't usually even think about bool being shorthand for System.Boolean, and it's good to be reminded of the deeper nuances of the language. Marc

                            V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                            1 Reply Last reply
                            0
                            • J Jon McKee

                              A little pointless but not too crazy. bool is just an alias for System.Boolean. The else was the silly part.

                              Boolean isOffset = new Boolean(); //default false
                              if (reader["foo"].ToString().ToUpper().Trim() == "BAR")
                              isOffset = Boolean.Parse(Boolean.TrueString);

                              Though I suspect unlike above that true and false are probably aliases for pre-defined constants. Couldn't find documentation on how they're created; above was just a guess using public Boolean members. Also true and false are operators that can be overloaded to create nullable types prior to .NET 2.0 (Nullable). Of course it's still silly to do it this way. bool is shorter to write and using true and false is both clearer and shorter.

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

                              FWIW while bool is "sort of a struct", like all primitive types instances of it are "created" (without any ctors being called) by MSIL instructions, eg `true` is created by ldc.i4.1 And `new bool()` *literally is* (not just sort of metaphysically/hypothetically according to an AS-IF rule but the literal compiler output) ldc.i4.0 I guess the moral of this story is that bool is int

                              J 1 Reply Last reply
                              0
                              • L Lost User

                                FWIW while bool is "sort of a struct", like all primitive types instances of it are "created" (without any ctors being called) by MSIL instructions, eg `true` is created by ldc.i4.1 And `new bool()` *literally is* (not just sort of metaphysically/hypothetically according to an AS-IF rule but the literal compiler output) ldc.i4.0 I guess the moral of this story is that bool is int

                                J Offline
                                J Offline
                                Jon McKee
                                wrote on last edited by
                                #18

                                Interesting. Looking at the CLI Specification[^] I.8.2.2 on page 46 that makes sense. Under all the abstraction it's an integer type.

                                1 Reply Last reply
                                0
                                • M Marc Clifton

                                  bool isOffset = new bool();
                                  if (reader["foo"].ToString().ToUpper().Trim() == "BAR")
                                  isOffset = true;
                                  else
                                  isOffset = false;

                                  I'll stop now. Marc

                                  V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

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

                                  Well, look: a variable must be initialized before it can be used. Now just imagine: somehow a third possibility comes into existence which is not covered by that if ... else - now you'll run into an error when you access isOffset because it was not initialized. :^)

                                  OriginalGriffO 1 Reply Last reply
                                  0
                                  • B Bernhard Hiller

                                    Well, look: a variable must be initialized before it can be used. Now just imagine: somehow a third possibility comes into existence which is not covered by that if ... else - now you'll run into an error when you access isOffset because it was not initialized. :^)

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

                                    So you want

                                    if (...)
                                    ...
                                    else
                                    ...
                                    maybe
                                    ...

                                    :laugh:

                                    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                                    "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

                                    J 1 Reply Last reply
                                    0
                                    • M Marc Clifton

                                      bool isOffset = new bool();
                                      if (reader["foo"].ToString().ToUpper().Trim() == "BAR")
                                      isOffset = true;
                                      else
                                      isOffset = false;

                                      I'll stop now. Marc

                                      V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

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

                                      Do you have a keyboard? Hit CTRL+A/Del and save us!

                                      Skipper: We'll fix it. Alex: Fix it? How you gonna fix this? Skipper: Grit, spit and a whole lotta duct tape.

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

                                      1 Reply Last reply
                                      0
                                      • M Marc Clifton

                                        bool isOffset = new bool();
                                        if (reader["foo"].ToString().ToUpper().Trim() == "BAR")
                                        isOffset = true;
                                        else
                                        isOffset = false;

                                        I'll stop now. Marc

                                        V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                                        Mike HankeyM Offline
                                        Mike HankeyM Offline
                                        Mike Hankey
                                        wrote on last edited by
                                        #22

                                        bool IsOffSet = new bool { improved };

                                        New version: WinHeist Version 2.2.2 Beta
                                        I told my psychiatrist that I was hearing voices in my head. He said you don't have a psychiatrist!

                                        1 Reply Last reply
                                        0
                                        • OriginalGriffO OriginalGriff

                                          So you want

                                          if (...)
                                          ...
                                          else
                                          ...
                                          maybe
                                          ...

                                          :laugh:

                                          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

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

                                          Reminds me of the fuzzy logic that was so popular in the beginning of the nineties.

                                          Wrong is evil and must be defeated. - Jeff Ello

                                          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