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. The Perfect Loop

The Perfect Loop

Scheduled Pinned Locked Moved The Weird and The Wonderful
collaborationcode-review
5 Posts 4 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.
  • R Offline
    R Offline
    Richard X Menezes
    wrote on last edited by
    #1

    I was doing a code review last week for a simple change which I had asked one of my team member to do. We were looping through the details of the File we downloaded and doing processing depending up whether it's type A or type B (This code was already there)

    foreach(MyfileInfo fil from files)
    {
    switch (fil.MyFileType)
    {
    case A:
    //Do some work for file A
    break;

      case B:
      //Do some work for file B
      break; 
    

    }
    }

    All That I had asked that person to do was to to change the way File B was processed. And this is what I got. :(

    foreach(MyfileInfo fil from files)
    {
    switch (fil.MyFileType)
    {
    case A:
    //Do some work for file A
    break;

      case B:
      **foreach(MyfileInfo fil2 from files)
      {
         switch (fil2.MyFileType)
         {
            case A:
            break;
    
            case B:
            //Do new work for File B.
            break;
         }
      }**
      break
    

    }
    }

    So if there were 50 files downloaded of type B the processing was happening 50*50= 2500 times :(( :((

    - Richard Menezes

    J B 2 Replies Last reply
    0
    • R Richard X Menezes

      I was doing a code review last week for a simple change which I had asked one of my team member to do. We were looping through the details of the File we downloaded and doing processing depending up whether it's type A or type B (This code was already there)

      foreach(MyfileInfo fil from files)
      {
      switch (fil.MyFileType)
      {
      case A:
      //Do some work for file A
      break;

        case B:
        //Do some work for file B
        break; 
      

      }
      }

      All That I had asked that person to do was to to change the way File B was processed. And this is what I got. :(

      foreach(MyfileInfo fil from files)
      {
      switch (fil.MyFileType)
      {
      case A:
      //Do some work for file A
      break;

        case B:
        **foreach(MyfileInfo fil2 from files)
        {
           switch (fil2.MyFileType)
           {
              case A:
              break;
      
              case B:
              //Do new work for File B.
              break;
           }
        }**
        break
      

      }
      }

      So if there were 50 files downloaded of type B the processing was happening 50*50= 2500 times :(( :((

      - Richard Menezes

      J Offline
      J Offline
      Jeroen De Dauw
      wrote on last edited by
      #2

      Why is he copying the code?! He could just call the function this stuff is in again, and have it be properly recursive as a bonus.

      Jeroen De Dauw (blog | Twitter | Identi.ca)

      1 Reply Last reply
      0
      • R Richard X Menezes

        I was doing a code review last week for a simple change which I had asked one of my team member to do. We were looping through the details of the File we downloaded and doing processing depending up whether it's type A or type B (This code was already there)

        foreach(MyfileInfo fil from files)
        {
        switch (fil.MyFileType)
        {
        case A:
        //Do some work for file A
        break;

          case B:
          //Do some work for file B
          break; 
        

        }
        }

        All That I had asked that person to do was to to change the way File B was processed. And this is what I got. :(

        foreach(MyfileInfo fil from files)
        {
        switch (fil.MyFileType)
        {
        case A:
        //Do some work for file A
        break;

          case B:
          **foreach(MyfileInfo fil2 from files)
          {
             switch (fil2.MyFileType)
             {
                case A:
                break;
        
                case B:
                //Do new work for File B.
                break;
             }
          }**
          break
        

        }
        }

        So if there were 50 files downloaded of type B the processing was happening 50*50= 2500 times :(( :((

        - Richard Menezes

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

        That is a really brilliant bit of code. :rolleyes:

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

        R 1 Reply Last reply
        0
        • B BillW33

          That is a really brilliant bit of code. :rolleyes:

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

          R Offline
          R Offline
          Richard X Menezes
          wrote on last edited by
          #4

          Completely agree to you. And am the one responsible for their deliverables, as I am their lead. :(

          Richard Menezes

          T 1 Reply Last reply
          0
          • R Richard X Menezes

            Completely agree to you. And am the one responsible for their deliverables, as I am their lead. :(

            Richard Menezes

            T Offline
            T Offline
            Tom Chantler
            wrote on last edited by
            #5

            Don't mention that there's an error, just show him the code and ask him why he shouldn't be fired for being a total moron! If he is actually any good, he'll laugh about it and say, "Oh yeah, you're right, maybe you'll have to let me go!"

            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