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. You'll be glad to know! [modified]

You'll be glad to know! [modified]

Scheduled Pinned Locked Moved The Lounge
csharpcsscomalgorithmsperformance
73 Posts 17 Posters 1 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.
  • S Super Lloyd

    there is the matter of avoiding goto, but this is no big deal, the real challenge is to do it in aesthetic and readable way! Well, I guess it's a subjective matter... But just to give you better chance, here is the real code. I think goto is the most elegant / beautiful solution. I invite you to show me the beauty of avoiding goto! (Although.. being a subjective thing... well....) Here we go:

    for (int i = max; i >= min; i--)
    {
    var v1 = new Vector2D(points[i > 0 ? i - 1 : points.Count - 1], points[i]);
    var v2 = new Vector2D(points[i], points[i < points.Count - 1 ? i + 1 : 0]);
    if (v1.SquareNorm <= MINL || v2.SquareNorm <= MINL)
    goto RemovePoint;
    v1 = v1.Normalize(); // divide by zero if test above fail
    v2 = v2.Normalize();
    var z = v1 ^ v2;
    if (Math.Abs(z) <= minsin && v1 * v2 < 0)
    goto RemovePoint;
    continue;
    RemovePoint: ;
    points.RemoveAt(i);
    if (points.Count < 3)
    return null;
    }

    A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

    modified on Thursday, September 9, 2010 8:31 PM

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

    If you really don't want to put some of that logic into functions, this is one way to go:

    for(...)
    {
    bool doRemove = false;
    var v1 = a();
    var v2 = b();
    if(v1.a() || v2.a())
    {
    doRemove = true;
    }
    else
    {
    v1 = c();
    v2 = d();
    var z = e();
    if(e(z, v1, v2))
    {
    doRemove = true;
    }
    }
    if(doRemove)
    {
    RemovePoint();
    }
    }

    I put in some placeholders where I didn't feel like typing.

    [Forum Guidelines]

    S 1 Reply Last reply
    0
    • P Peter_in_2780

      Two comments. 1. Loops are only nested too deep when you need to indent each level by less than [insert favourite small number here, mine's 4] spaces to fit it on the screen. ;P The construct

      if (!test)
      goto next;
      do_stuff;
      next:

      is actually what a compiler* will emit if you feed it

      if (test)
      do_stuff;

      Ironic, huh? But maybe that's why we deal in the input to compilers and leave their output unseen. * for a typical target instruction set

      Software rusts. Simon Stephenson, ca 1994.

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

      mmh... so you mean your way is better because it will compile to my way?!? ;P anyway, at this stage it's a matter of taste, your solution is elegant too! but too many bracket confuses me and the compiler in my brain! (as opposed to the one on the hard drive ;) )

      A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

      P 1 Reply Last reply
      0
      • S Super Lloyd

        see the code below! it can't be done upfront, as the first if will avoid as divide by zero in the second if! just for your benefit I post the code below again! Anyway, yes it can be done, but I found my way more readable... I guess it's too subjective for debate.. but I invite you to show me the new version:

        for (int i = max; i >= min; i--)
        {
        var v1 = new Vector2D(points[i > 0 ? i - 1 : points.Count - 1], points[i]);
        var v2 = new Vector2D(points[i], points[i < points.Count - 1 ? i + 1 : 0]);
        if (v1.SquareNorm <= MINL || v2.SquareNorm <= MINL)
        goto RemovePoint;
        v1 = v1.Normalize(); // divide by zero if square norm is 0 (test above)
        v2 = v2.Normalize();
        var z = v1 ^ v2;
        if (Math.Abs(z) <= minsin && v1 * v2 < 0)
        goto RemovePoint;
        continue;
        RemovePoint: ;
        points.RemoveAt(i);
        if (points.Count < 3)
        return null;
        }

        A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #34

        I already gave my preferred structure here[^], and I think we've had enough code in the Lounge for this week... :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        1 Reply Last reply
        0
        • A AspDotNetDev

          If you really don't want to put some of that logic into functions, this is one way to go:

          for(...)
          {
          bool doRemove = false;
          var v1 = a();
          var v2 = b();
          if(v1.a() || v2.a())
          {
          doRemove = true;
          }
          else
          {
          v1 = c();
          v2 = d();
          var z = e();
          if(e(z, v1, v2))
          {
          doRemove = true;
          }
          }
          if(doRemove)
          {
          RemovePoint();
          }
          }

          I put in some placeholders where I didn't feel like typing.

          [Forum Guidelines]

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

          ok, I guess this one will work and is readable! :thumbsup: but I still prefer my way! :laugh:

          A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

          M 1 Reply Last reply
          0
          • L Luc Pattyn

            Well, the complexity of avar1 = someCalculation(); isn't relevant, you can do it upfront anyway. The complexity of avar2 = someOtherCalculation(); is what matters. If it can't be put in the middle of the if clause, I'd use a boolean flag, like so:

            for (...) {
            bool updateWanted=false;
            if (calculation()==someValue) updateWanted=true;
            else if (someOtherCalculation()==someValue2) updateWanted=true;
            if (updateWanted) localVar.UpdateNicely();
            }

            and now you can easily expand line 4 (and 3) as required. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            modified on Thursday, September 9, 2010 8:52 PM

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

            mm.. I guess it's a nice simplification of other solution and it works AND is easily readable too!! :thumbsup: anyway, I still prefer my code! :laugh:

            A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

            1 Reply Last reply
            0
            • S Super Lloyd

              mmh... so you mean your way is better because it will compile to my way?!? ;P anyway, at this stage it's a matter of taste, your solution is elegant too! but too many bracket confuses me and the compiler in my brain! (as opposed to the one on the hard drive ;) )

              A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

              P Offline
              P Offline
              Peter_in_2780
              wrote on last edited by
              #37

              Super Lloyd wrote:

              your way is better because it will compile to my way

              What I am saying is that it's good for us that compilers can do the messy stuff, leaving us to express our algorithms in ways we can wrap our heads around without spewing. A couple of others have made similar comments in this thread. Enough with the philosophy! I'm outta here! ;P

              Software rusts. Simon Stephenson, ca 1994.

              1 Reply Last reply
              0
              • A AspDotNetDev

                The only acceptable place I've found for a goto is within a switch block. After all, the "labels" are already defined.

                [Forum Guidelines]

                C Offline
                C Offline
                Cesar de Souza
                wrote on last edited by
                #38

                I've found GOTO support specially useful when porting code from FORTRAN - or even from C. I guess this is one of the real excuses for having a GOTO instruction in C#: dealing with legacy code from languages were GOTO are/were common place. It just becomes much easier to port entire algorithms without having to change its structure in the process. Once an initial port is complete, it is much simpler to remove those offending instructions one by one (specially after you have set lots of regression tests). However, in some cases, removing all gotos just isn't worth the risk.

                Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines

                modified on Saturday, September 11, 2010 9:19 PM

                1 Reply Last reply
                0
                • S Super Lloyd

                  Ok, maybe I should say what I did, so maybe an anti-goto purist can give me tips on how to write goto-less nice code in such circumstances... (or become less anti goto) so here we go, that's what I wrote (veil your eyes, code in the lounge!)

                  for(...)
                  {
                  avar = calculation()
                  if(avar == someValue)
                  goto doStuff;
                  avar2 = someOtherCalculation();
                  if(avar2 == someValue2)
                  goto doStuff;
                  continue;
                  doStuff:;
                  localVar.UpdateNicely();
                  }

                  A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

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

                  Super Lloyd wrote:

                  can give me tips

                  well, most languages have the following capabilities: "else" methods can call methods "or" operations A combination of one or more of those language features would make your code a hell of a lot more readable and maintainable. ;) Marc

                  S 1 Reply Last reply
                  0
                  • S Super Lloyd

                    I thought about it and... despite my initial inflamatory intention I'm thinking we could both gain by showing you what I did, who knows one of 2 thing might even happen!! 1. maybe you'll think this is a good goto! 2. maybe you'll give me good work around so, here you go (veil your eyes, code in the lounge) please remove the goto in the nice fashion or hold your peace forever!

                    for(...)
                    {
                    avar = calculation()
                    if(avar == someValue)
                    goto doStuff;
                    avar2 = someOtherCalculation();
                    if(avar2 == someValue2)
                    goto doStuff;
                    continue;
                    doStuff:;
                    localVar.UpdateNicely();
                    }

                    A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                    S Offline
                    S Offline
                    Saurabh Garg
                    wrote on last edited by
                    #40

                    This is easy just put doStuff in another function. -Saurabh

                    1 Reply Last reply
                    0
                    • M Marc Clifton

                      Super Lloyd wrote:

                      can give me tips

                      well, most languages have the following capabilities: "else" methods can call methods "or" operations A combination of one or more of those language features would make your code a hell of a lot more readable and maintainable. ;) Marc

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

                      Maybe you an answer this other question. Somewhere I posted my real code and somewhere some posted the nested if version. Personally I found my version way simpler and maintainable. It has less line, less bracket, less variable a lower cyclomatic complexity. Now where does this "absolutely no goto" religion comes from? I just can't bring myself to prefer the nested if extra variable more lines of code version.... :omg: Anyway, I can see this is going no where. I did learn something, it's pointless to post against people belief, nothing came out of it! I haven't change my opinion, nor did they! and I'm upset!

                      A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                      P M 2 Replies Last reply
                      0
                      • S Super Lloyd

                        see the code below! it can't be done upfront, as the first if will avoid as divide by zero in the second if! just for your benefit I post the code below again! Anyway, yes it can be done, but I found my way more readable... I guess it's too subjective for debate.. but I invite you to show me the new version:

                        for (int i = max; i >= min; i--)
                        {
                        var v1 = new Vector2D(points[i > 0 ? i - 1 : points.Count - 1], points[i]);
                        var v2 = new Vector2D(points[i], points[i < points.Count - 1 ? i + 1 : 0]);
                        if (v1.SquareNorm <= MINL || v2.SquareNorm <= MINL)
                        goto RemovePoint;
                        v1 = v1.Normalize(); // divide by zero if square norm is 0 (test above)
                        v2 = v2.Normalize();
                        var z = v1 ^ v2;
                        if (Math.Abs(z) <= minsin && v1 * v2 < 0)
                        goto RemovePoint;
                        continue;
                        RemovePoint: ;
                        points.RemoveAt(i);
                        if (points.Count < 3)
                        return null;
                        }

                        A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                        Steve EcholsS Offline
                        Steve EcholsS Offline
                        Steve Echols
                        wrote on last edited by
                        #42

                        I'm not as much of a hater of goto's as most people, but without goto's I'd write it as:

                        for (int i = max; i >= min; i--)
                        {
                        bool removePoint = false;
                        var v1 = new Vector2D(points[i > 0 ? i - 1 : points.Count - 1], points[i]);
                        var v2 = new Vector2D(points[i], points[i < points.Count - 1 ? i + 1 : 0]);
                        if (v1.SquareNorm <= MINL || v2.SquareNorm <= MINL)
                        {
                        removePoint = true;
                        }
                        else
                        {
                        v1 = v1.Normalize(); // divide by zero if square norm is 0 (test above)
                        v2 = v2.Normalize();
                        var z = v1 ^ v2;
                        if (Math.Abs(z) <= minsin && v1 * v2 < 0)
                        removePoint = true;
                        }

                            if (removePoint)
                            {
                                points.RemoveAt(i);
                                if (points.Count < 3)
                                    return null;
                            }
                        

                        }

                        Either way, it's pretty clear. Yours doesn't require the extra allocation/initialization/assignment of the flag, so it's slightly more efficient, which could be important if you're in a huge loop.


                        - S 50 cups of coffee and you know it's on! Code, follow, or get out of the way.

                        • S
                          50 cups of coffee and you know it's on!
                          Code, follow, or get out of the way.
                        S L 2 Replies Last reply
                        0
                        • Steve EcholsS Steve Echols

                          I'm not as much of a hater of goto's as most people, but without goto's I'd write it as:

                          for (int i = max; i >= min; i--)
                          {
                          bool removePoint = false;
                          var v1 = new Vector2D(points[i > 0 ? i - 1 : points.Count - 1], points[i]);
                          var v2 = new Vector2D(points[i], points[i < points.Count - 1 ? i + 1 : 0]);
                          if (v1.SquareNorm <= MINL || v2.SquareNorm <= MINL)
                          {
                          removePoint = true;
                          }
                          else
                          {
                          v1 = v1.Normalize(); // divide by zero if square norm is 0 (test above)
                          v2 = v2.Normalize();
                          var z = v1 ^ v2;
                          if (Math.Abs(z) <= minsin && v1 * v2 < 0)
                          removePoint = true;
                          }

                              if (removePoint)
                              {
                                  points.RemoveAt(i);
                                  if (points.Count < 3)
                                      return null;
                              }
                          

                          }

                          Either way, it's pretty clear. Yours doesn't require the extra allocation/initialization/assignment of the flag, so it's slightly more efficient, which could be important if you're in a huge loop.


                          - S 50 cups of coffee and you know it's on! Code, follow, or get out of the way.

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

                          Glad to see that not everyone give in the anti goto dogma, an actually look at the code! :-D And yeah, I have been unconvinced by all the gymnastic to get rid of the goto so far. Seems much easier, shorter, etc... with it! I'm not really sure why I made this post in fact.. but I think I learn something about communication! :)

                          A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                          Steve EcholsS 1 Reply Last reply
                          0
                          • S Super Lloyd

                            I thought about it and... despite my initial inflamatory intention I'm thinking we could both gain by showing you what I did, who knows one of 2 thing might even happen!! 1. maybe you'll think this is a good goto! 2. maybe you'll give me good work around so, here you go (veil your eyes, code in the lounge) please remove the goto in the nice fashion or hold your peace forever!

                            for(...)
                            {
                            avar = calculation()
                            if(avar == someValue)
                            goto doStuff;
                            avar2 = someOtherCalculation();
                            if(avar2 == someValue2)
                            goto doStuff;
                            continue;
                            doStuff:;
                            localVar.UpdateNicely();
                            }

                            A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

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

                            Ouch.  I recommend:

                            for (...) {
                            avar = calculation();
                            if (avar == someValue) {
                            localVar.UpdateNicely();
                            }
                            else {
                            avar2 = someOtherCalculation();
                            if (avar2 == someValue2) {
                            localVar.UpdateNicely();
                            }
                            }
                            }

                            If avar and avar2 are purely local to the for, you could reduce this to:

                            for (...) {
                            if ((calculation() == someValue) || (someOtherCalculation() == someValue2)) {
                            localVar.UpdateNicely();
                            }
                            }

                            /ravi

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

                            S 1 Reply Last reply
                            0
                            • R Ravi Bhavnani

                              Ouch.  I recommend:

                              for (...) {
                              avar = calculation();
                              if (avar == someValue) {
                              localVar.UpdateNicely();
                              }
                              else {
                              avar2 = someOtherCalculation();
                              if (avar2 == someValue2) {
                              localVar.UpdateNicely();
                              }
                              }
                              }

                              If avar and avar2 are purely local to the for, you could reduce this to:

                              for (...) {
                              if ((calculation() == someValue) || (someOtherCalculation() == someValue2)) {
                              localVar.UpdateNicely();
                              }
                              }

                              /ravi

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

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

                              Real code here[^]. you could only do your first version. which I find more cumbersome than the goto version because: - it has more bracket and line of code - some code is repeated (localvar.UpdateNicel() contains, in fact, a conditional return, hence it can't be put into a function) In fact the version with goto is the best or equals to all other solution in term of - number of line of code (less) - number of if (less) - number of nested block (less) - number of variables (less)

                              A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                              1 Reply Last reply
                              0
                              • S Super Lloyd

                                ok, I guess this one will work and is readable! :thumbsup: but I still prefer my way! :laugh:

                                A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

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

                                Super Lloyd wrote:

                                but I still prefer my way

                                Of course you do, it is yours after all. Be prepared to defend a law suit some years down the track when a support dev has a heart attack when they see it. At which point the thing will be refactored to something sensible. And yes I'm one of those who will go to extreme lengths to eliminate goto.

                                Never underestimate the power of human stupidity RAH

                                1 Reply Last reply
                                0
                                • S Super Lloyd

                                  Maybe you an answer this other question. Somewhere I posted my real code and somewhere some posted the nested if version. Personally I found my version way simpler and maintainable. It has less line, less bracket, less variable a lower cyclomatic complexity. Now where does this "absolutely no goto" religion comes from? I just can't bring myself to prefer the nested if extra variable more lines of code version.... :omg: Anyway, I can see this is going no where. I did learn something, it's pointless to post against people belief, nothing came out of it! I haven't change my opinion, nor did they! and I'm upset!

                                  A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                                  P Offline
                                  P Offline
                                  Patrick Klug
                                  wrote on last edited by
                                  #47

                                  If you don't like brackets, refactor the nested loop into another method. The way I see it you just WANT to use goto's even though you know that 'most other people' (TM) would prefer the equally valid version without goto's. Personally it upsets me that people use language features for no good reason. 'I don't like brackets' is not a good reason at all. Code with a goto is always harder to decipher than code without.

                                  S 2 Replies Last reply
                                  0
                                  • S Super Lloyd

                                    Glad to see that not everyone give in the anti goto dogma, an actually look at the code! :-D And yeah, I have been unconvinced by all the gymnastic to get rid of the goto so far. Seems much easier, shorter, etc... with it! I'm not really sure why I made this post in fact.. but I think I learn something about communication! :)

                                    A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                                    Steve EcholsS Offline
                                    Steve EcholsS Offline
                                    Steve Echols
                                    wrote on last edited by
                                    #48

                                    Right on. If you start using nested gotos, or didn't label them nicely, I'd have to hire JSOP to come after you. :-D Remember, it's all good code, until you have to maintain it. Double :-D


                                    - S 50 cups of coffee and you know it's on! Code, follow, or get out of the way.

                                    • S
                                      50 cups of coffee and you know it's on!
                                      Code, follow, or get out of the way.
                                    1 Reply Last reply
                                    0
                                    • P Patrick Klug

                                      If you don't like brackets, refactor the nested loop into another method. The way I see it you just WANT to use goto's even though you know that 'most other people' (TM) would prefer the equally valid version without goto's. Personally it upsets me that people use language features for no good reason. 'I don't like brackets' is not a good reason at all. Code with a goto is always harder to decipher than code without.

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

                                      Basically you don't want goto, why do I need to do as you like? No compelling reason so far!

                                      A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                                      1 Reply Last reply
                                      0
                                      • P Patrick Klug

                                        If you don't like brackets, refactor the nested loop into another method. The way I see it you just WANT to use goto's even though you know that 'most other people' (TM) would prefer the equally valid version without goto's. Personally it upsets me that people use language features for no good reason. 'I don't like brackets' is not a good reason at all. Code with a goto is always harder to decipher than code without.

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

                                        In fact, I noticed you gave an argument: "is harder to decipher" It's a good argument, it just happen I find the goto version more readable! There is nothing much to say...

                                        A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                                        1 Reply Last reply
                                        0
                                        • S Super Lloyd

                                          Yesterday I wrote no less than 2 gotos in my C# code! [Edit2] This guy[^] found a satisfying refactoring! One which doesn't tax my (limited brain) memory with nested block, additional variable, additional test, increased cyclomatic complexity! (In fact the cyclomatic complexity is reduced by 1, I think) Well done! :thumbsup: :cool: :-D [EDIT] For your information the real code is below. So far no one has come up with a non goto version which can beat the goto version on any of those 4 criteria: - number of line of code (less) - number of if (less) - number of nested block (less) - number of variables (less) -- code --

                                          for (int i = max; i >= min; i--)
                                          {
                                          var v1 = new Vector2D(points[i > 0 ? i - 1 : points.Count - 1], points[i]);
                                          var v2 = new Vector2D(points[i], points[i < points.Count - 1 ? i + 1 : 0]);
                                          if (v1.SquareNorm <= MINL || v2.SquareNorm <= MINL)
                                          goto RemovePoint;
                                          v1 = v1.Normalize(); // divide by zero if square norm is 0 (test above)
                                          v2 = v2.Normalize();
                                          var z = v1 ^ v2;
                                          if (Math.Abs(z) <= minsin && v1 * v2 < 0)
                                          goto RemovePoint;
                                          continue;
                                          RemovePoint: ;
                                          points.RemoveAt(i);
                                          if (points.Count < 3)
                                          return null;
                                          }

                                          A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                                          modified on Friday, September 10, 2010 10:53 AM

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

                                          Super Lloyd wrote:

                                          So far no one has come up with a non goto version which can beat the goto version on any of those 4 criteria: - number of line of code (less) - number of if (less) - number of nested block (less) - number of variables (less)

                                          Um, setting arbitrary rules to suit your purpose only shows that you've used goto for arbitrary purposes. Cheers, Drew.

                                          S 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