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. Code Repeating

Code Repeating

Scheduled Pinned Locked Moved The Weird and The Wonderful
javascripthtmlalgorithmsbusinessperformance
8 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.
  • M Offline
    M Offline
    Mohibur Rashid
    wrote on last edited by
    #1

    Take a look at the algorithm

    function Process()
    {
    if(error!="")
    {
    // Some HTML code over 1000 lines with javascript
    }
    else if(update!="")
    {
    // Same like above :o with same f-king javascript
    }
    else
    {
    // Same 1000 of lines with same javascript.
    }
    }

    now my job is to make some change, for new requirements. the file is over 4000 lines. And reading over hour I actually failed to figure out how actually it works. Authority got that reason, I am not good enough. I agreed with them. Oh the reason to change the code was "Performance and incomplete verification"

    R N 2 Replies Last reply
    0
    • M Mohibur Rashid

      Take a look at the algorithm

      function Process()
      {
      if(error!="")
      {
      // Some HTML code over 1000 lines with javascript
      }
      else if(update!="")
      {
      // Same like above :o with same f-king javascript
      }
      else
      {
      // Same 1000 of lines with same javascript.
      }
      }

      now my job is to make some change, for new requirements. the file is over 4000 lines. And reading over hour I actually failed to figure out how actually it works. Authority got that reason, I am not good enough. I agreed with them. Oh the reason to change the code was "Performance and incomplete verification"

      R Offline
      R Offline
      RobCroll
      wrote on last edited by
      #2

      Be very careful with code like this. You think it's the same 1000 lines but you may find one line has been changed. Seen this rubbish many times before, if you refractor to make sense of it, you'll miss that one line.

      "You get that on the big jobs."

      M 1 Reply Last reply
      0
      • M Mohibur Rashid

        Take a look at the algorithm

        function Process()
        {
        if(error!="")
        {
        // Some HTML code over 1000 lines with javascript
        }
        else if(update!="")
        {
        // Same like above :o with same f-king javascript
        }
        else
        {
        // Same 1000 of lines with same javascript.
        }
        }

        now my job is to make some change, for new requirements. the file is over 4000 lines. And reading over hour I actually failed to figure out how actually it works. Authority got that reason, I am not good enough. I agreed with them. Oh the reason to change the code was "Performance and incomplete verification"

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

        Following from rob, take the three code blocks and diff them.


        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

        L 1 Reply Last reply
        0
        • N Nagy Vilmos

          Following from rob, take the three code blocks and diff them.


          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

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

          Or even better, throw them away. Rewriting from scratch can be less work in such cases.

          And from the clouds a mighty voice spoke:
          "Smile and be happy, for it could come worse!"

          And I smiled and was happy
          And it came worse.

          M 1 Reply Last reply
          0
          • R RobCroll

            Be very careful with code like this. You think it's the same 1000 lines but you may find one line has been changed. Seen this rubbish many times before, if you refractor to make sense of it, you'll miss that one line.

            "You get that on the big jobs."

            M Offline
            M Offline
            Mohibur Rashid
            wrote on last edited by
            #5

            Yep I was worried about that too and I know the differences. And thinking of future I redesigned the entire page. Now even I need to change its only one function.

            F 1 Reply Last reply
            0
            • L Lost User

              Or even better, throw them away. Rewriting from scratch can be less work in such cases.

              And from the clouds a mighty voice spoke:
              "Smile and be happy, for it could come worse!"

              And I smiled and was happy
              And it came worse.

              M Offline
              M Offline
              Mohibur Rashid
              wrote on last edited by
              #6

              Thats waht I did

              1 Reply Last reply
              0
              • M Mohibur Rashid

                Yep I was worried about that too and I know the differences. And thinking of future I redesigned the entire page. Now even I need to change its only one function.

                F Offline
                F Offline
                fjdiewornncalwe
                wrote on last edited by
                #7

                As Rob says, make sure you are entirely sure of any changes between blocks and that they are maintained. I have encountered this many times while translating old classic asp applications to newer dotNet. I found that by splitting each of the cases into a separate text file and then running diffs on them tends to make the job much easier. The good part is that most devs who have done this used copy-paste and then made their modifications, so there is some hope for them yet...

                I wasn't, now I am, then I won't be anymore.

                B 1 Reply Last reply
                0
                • F fjdiewornncalwe

                  As Rob says, make sure you are entirely sure of any changes between blocks and that they are maintained. I have encountered this many times while translating old classic asp applications to newer dotNet. I found that by splitting each of the cases into a separate text file and then running diffs on them tends to make the job much easier. The good part is that most devs who have done this used copy-paste and then made their modifications, so there is some hope for them yet...

                  I wasn't, now I am, then I won't be anymore.

                  B Offline
                  B Offline
                  BobJanova
                  wrote on last edited by
                  #8

                  I was going to suggest exactly this little trick. It can really help with refactoring old crap.

                  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