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. Get all the Enumeratorz

Get all the Enumeratorz

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpcareer
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jacek M Glen
    wrote on last edited by
    #1

    I moved to a new job a couple of months ago. I'm working on extending existing product. It's quite mature as it's been developed for the past decade, so the code base is rather large. Many times often I need to dig into existing code. I find some strange things there, just a moment ago I found:

    public override void ReverseProcess()
    {
    List actionsList;
    // get actions
    var actionsEnumerator = actionsList.GetEnumerator();
    actionsEnumerator.Reset();
    ReverseActions(actionsEnumerator);
    }

    private void ReverseActions(IEnumerator actionsEnumerator)
    {
    while (actionsEnumerator.MoveNext())
    {
    automatedActionEO = (AutomatedActionEO)actionsEnumerator.Current;
    //process action
    }
    }

    The code was written in 2013, so either someone is stacked on .NET 1.1 or thought that using GetEnumerator() in that way looks smart in the code, i.e. as if they knew some inner mechanisms of collections ;) There's a lot of weird things like this one in the inherited code. Most of them not harmful, just weird.

    F V J B 4 Replies Last reply
    0
    • J Jacek M Glen

      I moved to a new job a couple of months ago. I'm working on extending existing product. It's quite mature as it's been developed for the past decade, so the code base is rather large. Many times often I need to dig into existing code. I find some strange things there, just a moment ago I found:

      public override void ReverseProcess()
      {
      List actionsList;
      // get actions
      var actionsEnumerator = actionsList.GetEnumerator();
      actionsEnumerator.Reset();
      ReverseActions(actionsEnumerator);
      }

      private void ReverseActions(IEnumerator actionsEnumerator)
      {
      while (actionsEnumerator.MoveNext())
      {
      automatedActionEO = (AutomatedActionEO)actionsEnumerator.Current;
      //process action
      }
      }

      The code was written in 2013, so either someone is stacked on .NET 1.1 or thought that using GetEnumerator() in that way looks smart in the code, i.e. as if they knew some inner mechanisms of collections ;) There's a lot of weird things like this one in the inherited code. Most of them not harmful, just weird.

      F Offline
      F Offline
      Freak30
      wrote on last edited by
      #2

      Where exactly is the "reverse" part? For me this looks like the actions are processed in the normal forward order.

      The good thing about pessimism is, that you are always either right or pleasently surprised.

      Richard DeemingR 1 Reply Last reply
      0
      • F Freak30

        Where exactly is the "reverse" part? For me this looks like the actions are processed in the normal forward order.

        The good thing about pessimism is, that you are always either right or pleasently surprised.

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        My guess would be that it's "reverse" as in "undo", not "reverse" as in "go backwards".


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        1 Reply Last reply
        0
        • J Jacek M Glen

          I moved to a new job a couple of months ago. I'm working on extending existing product. It's quite mature as it's been developed for the past decade, so the code base is rather large. Many times often I need to dig into existing code. I find some strange things there, just a moment ago I found:

          public override void ReverseProcess()
          {
          List actionsList;
          // get actions
          var actionsEnumerator = actionsList.GetEnumerator();
          actionsEnumerator.Reset();
          ReverseActions(actionsEnumerator);
          }

          private void ReverseActions(IEnumerator actionsEnumerator)
          {
          while (actionsEnumerator.MoveNext())
          {
          automatedActionEO = (AutomatedActionEO)actionsEnumerator.Current;
          //process action
          }
          }

          The code was written in 2013, so either someone is stacked on .NET 1.1 or thought that using GetEnumerator() in that way looks smart in the code, i.e. as if they knew some inner mechanisms of collections ;) There's a lot of weird things like this one in the inherited code. Most of them not harmful, just weird.

          V Offline
          V Offline
          Vladimir Svyatski
          wrote on last edited by
          #4

          The foreach operator is not an option I guess :) . Also, if they only wanted to reverse the list, why not use this? That is the forbidden stuff, and the unfaithful will be punished by torturing and banishing for forever.

          I have 4 words for you: I love this company! Yes!

          1 Reply Last reply
          0
          • J Jacek M Glen

            I moved to a new job a couple of months ago. I'm working on extending existing product. It's quite mature as it's been developed for the past decade, so the code base is rather large. Many times often I need to dig into existing code. I find some strange things there, just a moment ago I found:

            public override void ReverseProcess()
            {
            List actionsList;
            // get actions
            var actionsEnumerator = actionsList.GetEnumerator();
            actionsEnumerator.Reset();
            ReverseActions(actionsEnumerator);
            }

            private void ReverseActions(IEnumerator actionsEnumerator)
            {
            while (actionsEnumerator.MoveNext())
            {
            automatedActionEO = (AutomatedActionEO)actionsEnumerator.Current;
            //process action
            }
            }

            The code was written in 2013, so either someone is stacked on .NET 1.1 or thought that using GetEnumerator() in that way looks smart in the code, i.e. as if they knew some inner mechanisms of collections ;) There's a lot of weird things like this one in the inherited code. Most of them not harmful, just weird.

            J Offline
            J Offline
            jibalt
            wrote on last edited by
            #5

            There's nothing wrong with that code (other than it being called Reverse rather than Undo), if ReverseActions is called elsewhere with a partially enumerated IEnumerator ... which I'd bet it is.

            1 Reply Last reply
            0
            • J Jacek M Glen

              I moved to a new job a couple of months ago. I'm working on extending existing product. It's quite mature as it's been developed for the past decade, so the code base is rather large. Many times often I need to dig into existing code. I find some strange things there, just a moment ago I found:

              public override void ReverseProcess()
              {
              List actionsList;
              // get actions
              var actionsEnumerator = actionsList.GetEnumerator();
              actionsEnumerator.Reset();
              ReverseActions(actionsEnumerator);
              }

              private void ReverseActions(IEnumerator actionsEnumerator)
              {
              while (actionsEnumerator.MoveNext())
              {
              automatedActionEO = (AutomatedActionEO)actionsEnumerator.Current;
              //process action
              }
              }

              The code was written in 2013, so either someone is stacked on .NET 1.1 or thought that using GetEnumerator() in that way looks smart in the code, i.e. as if they knew some inner mechanisms of collections ;) There's a lot of weird things like this one in the inherited code. Most of them not harmful, just weird.

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

              Looks like the code will work and is more justification for my signature line. :)

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

              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