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 72 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 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
        • 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.

          E Offline
          E Offline
          ekolis
          wrote on last edited by
          #31

          And the IIf function doesn't even have a short-circuit version! If you're used to writing code like this in C#:

          int count = list == null ? 0 : list.Count;

          and you try to translate to VB:

          dim count as integer = iif(list is nothing, 0, list.Count)

          you will wind up with a NullReferenceException when list is null/nothing!

          L 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

            E Offline
            E Offline
            ekolis
            wrote on last edited by
            #32

            I think F# has something similar to this... in other languages you have to mess with funky generic type constraints or templates or whatever you have available :(

            1 Reply Last reply
            0
            • E ekolis

              And the IIf function doesn't even have a short-circuit version! If you're used to writing code like this in C#:

              int count = list == null ? 0 : list.Count;

              and you try to translate to VB:

              dim count as integer = iif(list is nothing, 0, list.Count)

              you will wind up with a NullReferenceException when list is null/nothing!

              L Offline
              L Offline
              LetMeFinclOut
              wrote on last edited by
              #33

              Actually, since VB 2008, that's no longer true. The If Operator (without the extra I) The 3 parameter form act like the C# ternary operator ? :, while the 2 parameter form would be the C# coalesce ??. But yes, TRWTF is VB.

              E 1 Reply Last reply
              0
              • Z ZurdoDev

                True object-oriented programming allows it because they are all objects. It doesn't care.

                L Offline
                L Offline
                LetMeFinclOut
                wrote on last edited by
                #34

                God I really...REALLY hope that you're just trolling.

                1 Reply Last reply
                0
                • L LetMeFinclOut

                  Actually, since VB 2008, that's no longer true. The If Operator (without the extra I) The 3 parameter form act like the C# ternary operator ? :, while the 2 parameter form would be the C# coalesce ??. But yes, TRWTF is VB.

                  E Offline
                  E Offline
                  ekolis
                  wrote on last edited by
                  #35

                  Wow, you learn something new every day :) Funny how the documentation lists the 2-parameter form's arguments as argument2 and argument3, though...

                  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
                    Mohibur Rashid
                    wrote on last edited by
                    #36

                    You Remind me my Old company. Joining them I started developing with VB6. In my Project I did the entire project keeping Option Explicit on. Then I gave that entire project to my Senior. Then he complained: Hey I cannot program, its making error. ?????????????????? what ????

                    I know I am coward since the day I know that fortune favors the brave

                    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

                      L Offline
                      L Offline
                      LetMeFinclOut
                      wrote on last edited by
                      #37

                      Jörgen Andersson wrote:

                      Naerling wrote:

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

                      Then you need to start fixring now. ...snip... If it's not the highest priority your company has problems.

                      FTFY

                      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