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. Strictly Short Circuit

Strictly Short Circuit

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpcomhelp
37 Posts 20 Posters 37 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.
  • A AspDotNetDev

    Names changed to protect the innocent... I'm working with some VB.net projects and I decided to turn on Option Strict. It threw an error for this line:

    If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value OrElse someProp.Value = "0") Then

    This is what was intended:

    If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value) OrElse someProp.Value = "0" Then

    :-D for option explicit! :(( for the fact that I have several projects to go and I'm working in the order of best code to worst code.

    Thou mewling ill-breeding pignut!

    Y Offline
    Y Offline
    YvesDaoust
    wrote on last edited by
    #11

    Computers should be used for what they are good at: systematic consistency checks. Because this is where they can help preventing bugs early. Static analysis. If I were God, I would make the Strict mode compulsory. And enhance the programming languages to help computers help us. For instance by introducing dimensional analysis on the data.

    Dim Meters as Unit
    Dim Side As Integer in Meters, Area As Integer in Meters^2, Count(0 To 5) As Integer

    Area = 3 * Side 'Error: Option Strict On disallows implicit conversion from Meters to Meters^2
    Count(Side) = Count(Side) + 1 'Error: Option Strict On disallows using dimensional expressions as indexes

    P E 2 Replies Last reply
    0
    • A AspDotNetDev

      Names changed to protect the innocent... I'm working with some VB.net projects and I decided to turn on Option Strict. It threw an error for this line:

      If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value OrElse someProp.Value = "0") Then

      This is what was intended:

      If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value) OrElse someProp.Value = "0" Then

      :-D for option explicit! :(( for the fact that I have several projects to go and I'm working in the order of best code to worst code.

      Thou mewling ill-breeding pignut!

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

      I feel your pain! Our company has a product where turning Option Strict On results in probably 1000's of errors... Stuff like:

      Dim i As Integer = someStringThatSupposedlyCanOnlyHoldAnInteger

      The worst part is that code like this goes wrong on regular basis. Our users will never know though... Errors are caught and logged (preferably at the lowerst level, some 10 functions deep) and the software goes on like nothing ever happened :)

      It's an OO world.

      public class Naerling : Lazy<Person>{
      public void DoWork(){ throw new NotImplementedException(); }
      }

      J 1 Reply Last reply
      0
      • Y YvesDaoust

        Computers should be used for what they are good at: systematic consistency checks. Because this is where they can help preventing bugs early. Static analysis. If I were God, I would make the Strict mode compulsory. And enhance the programming languages to help computers help us. For instance by introducing dimensional analysis on the data.

        Dim Meters as Unit
        Dim Side As Integer in Meters, Area As Integer in Meters^2, Count(0 To 5) As Integer

        Area = 3 * Side 'Error: Option Strict On disallows implicit conversion from Meters to Meters^2
        Count(Side) = Count(Side) + 1 'Error: Option Strict On disallows using dimensional expressions as indexes

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

        That should be possible with OOP. A Lounge post earlier in the week led me to a paper written by C. A. R. Hoare in 1973 in which he states that a language should allow that: http://www.eecs.umich.edu/~bchandra/courses/papers/Hoare_Hints.pdf[^]

        Y F 2 Replies Last reply
        0
        • P PIEBALDconsult

          That should be possible with OOP. A Lounge post earlier in the week led me to a paper written by C. A. R. Hoare in 1973 in which he states that a language should allow that: http://www.eecs.umich.edu/~bchandra/courses/papers/Hoare_Hints.pdf[^]

          Y Offline
          Y Offline
          YvesDaoust
          wrote on last edited by
          #14

          Thanks for pointing at this article: a pure delight ! As is turns out, little of Hoare's hints have been followed, I guess :)

          1 Reply Last reply
          0
          • Sander RosselS Sander Rossel

            I feel your pain! Our company has a product where turning Option Strict On results in probably 1000's of errors... Stuff like:

            Dim i As Integer = someStringThatSupposedlyCanOnlyHoldAnInteger

            The worst part is that code like this goes wrong on regular basis. Our users will never know though... Errors are caught and logged (preferably at the lowerst level, some 10 functions deep) and the software goes on like nothing ever happened :)

            It's an OO world.

            public class Naerling : Lazy<Person>{
            public void DoWork(){ throw new NotImplementedException(); }
            }

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

            Naerling wrote:

            Our company has a product where turning Option Strict On results in probably 1000's of errors

            Then you need to start fixing now. Enable it on file level and fix the files one by one. If it's not the highest priority your company has problems.

            Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

            N Sander RosselS L 3 Replies Last reply
            0
            • C cpkilekofp

              AspDotNetDev wrote:

              The bad part is that the OrElse is between a string and a boolean, which is returning a boolean, which then gets passed as a parameter to String.IsNullOrEmpty.

              Uh, that's WHY there is an Option Strict: to allow relaxed type checking on certain operations. Though here it is certainly annoying, and one of the reasons I tend to use Option Strict pretty consistently.

              J Offline
              J Offline
              Jan Steyn
              wrote on last edited by
              #16

              I have never programmed in VB without Option Strict and Option Explicit turned on. That is the only way that VB doesn't turn into an absolute nightmare.

              K 1 Reply Last reply
              0
              • J Jorgen Andersson

                Naerling wrote:

                Our company has a product where turning Option Strict On results in probably 1000's of errors

                Then you need to start fixing now. Enable it on file level and fix the files one by one. If it's not the highest priority your company has problems.

                Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

                N Offline
                N Offline
                Nagy Vilmos
                wrote on last edited by
                #17

                In the old VB days, I worked on a project and we mandated Option Explicit for all files. One dev kept removing it as his code wouldn't build when it was switched on...


                Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                J 1 Reply Last reply
                0
                • N Nagy Vilmos

                  In the old VB days, I worked on a project and we mandated Option Explicit for all files. One dev kept removing it as his code wouldn't build when it was switched on...


                  Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

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

                  How did you punish him?

                  Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

                  N 1 Reply Last reply
                  0
                  • A AspDotNetDev

                    Using a string as a boolean has nothing to do with object-oriented programming. If the code were directly comparing the boolean and the string, that might be considered something near valid (what with operator overloading), but that was not the case here. This code is basically like doing this:

                    If "Dragons" Then
                    ' Dragons be true!
                    Else
                    ' Dragons be false :-(
                    End If

                    It doesn't make any sense.

                    Thou mewling ill-breeding pignut!

                    D Offline
                    D Offline
                    dawmail333
                    wrote on last edited by
                    #19

                    Someone doesn't use PHP.

                    Don't forget to rate my post if it helped! ;) "He has no enemies, but is intensely disliked by his friends." "His mother should have thrown him away, and kept the stork." "There's nothing wrong with you that reincarnation won't cure." "He loves nature, in spite of what it did to him."

                    A 1 Reply Last reply
                    0
                    • J Jorgen Andersson

                      How did you punish him?

                      Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

                      N Offline
                      N Offline
                      Nagy Vilmos
                      wrote on last edited by
                      #20

                      It was a long process of giving him a roll kick to the nadgers every time he checked in a file without Option Explicit. We needed to have a rota.


                      Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                      1 Reply Last reply
                      0
                      • A AspDotNetDev

                        Names changed to protect the innocent... I'm working with some VB.net projects and I decided to turn on Option Strict. It threw an error for this line:

                        If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value OrElse someProp.Value = "0") Then

                        This is what was intended:

                        If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value) OrElse someProp.Value = "0" Then

                        :-D for option explicit! :(( for the fact that I have several projects to go and I'm working in the order of best code to worst code.

                        Thou mewling ill-breeding pignut!

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

                        The Law of Missing Parentheses: Keep adding closing parenthesis at the end till the compiler stops complaining about them. :-)

                        1 Reply Last reply
                        0
                        • J Jan Steyn

                          I have never programmed in VB without Option Strict and Option Explicit turned on. That is the only way that VB doesn't turn into an absolute nightmare.

                          K Offline
                          K Offline
                          K Quinn
                          wrote on last edited by
                          #22

                          I agree. (VB is a nightmare anyways, but point well taken)

                          1 Reply Last reply
                          0
                          • P PIEBALDconsult

                            That should be possible with OOP. A Lounge post earlier in the week led me to a paper written by C. A. R. Hoare in 1973 in which he states that a language should allow that: http://www.eecs.umich.edu/~bchandra/courses/papers/Hoare_Hints.pdf[^]

                            F Offline
                            F Offline
                            Fabio Franco
                            wrote on last edited by
                            #23

                            The paper doesn't seem to mention anything about implicit conversion on two incompatible types. And even so, implicit conversion can be implemented on a type so two incompatible types become compatible, but the conversion is implemented by a custom algorithm. I still think that should never be allowed.

                            "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

                            1 Reply Last reply
                            0
                            • A AspDotNetDev

                              Names changed to protect the innocent... I'm working with some VB.net projects and I decided to turn on Option Strict. It threw an error for this line:

                              If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value OrElse someProp.Value = "0") Then

                              This is what was intended:

                              If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value) OrElse someProp.Value = "0" Then

                              :-D for option explicit! :(( for the fact that I have several projects to go and I'm working in the order of best code to worst code.

                              Thou mewling ill-breeding pignut!

                              M Offline
                              M Offline
                              Marbry Hardin
                              wrote on last edited by
                              #24

                              This is why it's good to always explcitly define your intentions with the proper parenthesis. It makes it easier to detect mistakes like that and for someone else to read and deduce your intent. You can easily produce similar errors in logical grouping in C# or other languages. Even if not with that particular syntax. ;-)

                              1 Reply Last reply
                              0
                              • A AspDotNetDev

                                Yeah, the real horror is that VB.net allows that at all.

                                Thou mewling ill-breeding pignut!

                                A Offline
                                A Offline
                                agolddog
                                wrote on last edited by
                                #25

                                Slight disagreement. The real horror is that the developer has to specify, "Yes, please use short-circuit boolean logic" by using OrElse instead of that being the default behavior.

                                P E 2 Replies Last reply
                                0
                                • D dawmail333

                                  Someone doesn't use PHP.

                                  Don't forget to rate my post if it helped! ;) "He has no enemies, but is intensely disliked by his friends." "His mother should have thrown him away, and kept the stork." "There's nothing wrong with you that reincarnation won't cure." "He loves nature, in spite of what it did to him."

                                  A Offline
                                  A Offline
                                  AspDotNetDev
                                  wrote on last edited by
                                  #26

                                  That's because somebody read a PHP book, puked in his mouth, and is still trying to wash away the filth.

                                  Thou mewling ill-breeding pignut!

                                  1 Reply Last reply
                                  0
                                  • A AspDotNetDev

                                    Names changed to protect the innocent... I'm working with some VB.net projects and I decided to turn on Option Strict. It threw an error for this line:

                                    If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value OrElse someProp.Value = "0") Then

                                    This is what was intended:

                                    If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value) OrElse someProp.Value = "0" Then

                                    :-D for option explicit! :(( for the fact that I have several projects to go and I'm working in the order of best code to worst code.

                                    Thou mewling ill-breeding pignut!

                                    P Offline
                                    P Offline
                                    Patrick Fox
                                    wrote on last edited by
                                    #27

                                    Option strict FTW! Option strict all the way! Option strict is the first thing I turn on when anyone hands me a VB.Net project. I'll say it a million times: I would rather get a compile time error than a runtime error. Option strict won't flag every possible runtime error, but it will flag most of the boneheaded ones.

                                    1 Reply Last reply
                                    0
                                    • A agolddog

                                      Slight disagreement. The real horror is that the developer has to specify, "Yes, please use short-circuit boolean logic" by using OrElse instead of that being the default behavior.

                                      P Offline
                                      P Offline
                                      Patrick Fox
                                      wrote on last edited by
                                      #28

                                      You mean like it is in every other language? The way it should be?

                                      1 Reply Last reply
                                      0
                                      • A AspDotNetDev

                                        Names changed to protect the innocent... I'm working with some VB.net projects and I decided to turn on Option Strict. It threw an error for this line:

                                        If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value OrElse someProp.Value = "0") Then

                                        This is what was intended:

                                        If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value) OrElse someProp.Value = "0" Then

                                        :-D for option explicit! :(( for the fact that I have several projects to go and I'm working in the order of best code to worst code.

                                        Thou mewling ill-breeding pignut!

                                        S Offline
                                        S Offline
                                        sergiogarcianinja
                                        wrote on last edited by
                                        #29

                                        I can develop in more than 10 language (actually, I don't know exactly how much languages I now, I always forgot some) and I have no preference for the best language. Almost all the time I use C#, but I use others as needed if the moment needs and it pays my bills. But, I really don't like VB at all. I know VB since VB 5.0 (or 3.0, I don't remember, the year was 98) and these syntax flaws are really annoying. The VB (also VB .net) rounding is also terribly, all languages that I know truncate integer division and VB round it. The backwards compatibility of VB .net with VB 6 projects made VB .net a horrible language. I'm really experienced with VB (and VB .net) and it's a pain to correct legacy code in this language, so good luck!

                                        1 Reply Last reply
                                        0
                                        • J Jorgen Andersson

                                          Naerling wrote:

                                          Our company has a product where turning Option Strict On results in probably 1000's of errors

                                          Then you need to start fixing now. Enable it on file level and fix the files one by one. If it's not the highest priority your company has problems.

                                          Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

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

                                          Jörgen Andersson wrote:

                                          If it's not the highest priority your company has problems.

                                          If we make it our highest priority we'll be fixing software that 'works' as far as the customer is concerned. We won't be able to make new software anytime soon. We won't have any revenues for the coming months, just fixes that might not fix all they were supposed to fix. And lots of angry customers. No, if we made it our top priority THEN we have a problem... I might not be happy with it, my boss might not be happy with it, but that's just the way it is. Luckily, any new software we built is built with option strict on :)

                                          It's an OO world.

                                          public class Naerling : Lazy<Person>{
                                          public void DoWork(){ throw new NotImplementedException(); }
                                          }

                                          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