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. Horrible enough for you?

Horrible enough for you?

Scheduled Pinned Locked Moved The Weird and The Wonderful
javascriptdata-structuresquestion
22 Posts 14 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.
  • D Offline
    D Offline
    dojohansen
    wrote on last edited by
    #1

    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("block_name").cloneNode(true)); } catch(e) {};
    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("block_type").cloneNode(true)); } catch(e) {};
    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("title").cloneNode(true)); } catch(e) {};
    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("list_id").cloneNode(true)); } catch(e) {};
    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("format_number").cloneNode(true));} catch(e) {};
    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("format_force").cloneNode(true));} catch(e) {};
    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("visible").cloneNode(true));} catch(e) {};
    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("titre").cloneNode(true));} catch(e) {};
    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_width").cloneNode(true));} catch(e) {};
    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_sens").cloneNode(true));} catch(e) {};
    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_data_type").cloneNode(true));} catch(e) {};
    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("locked").cloneNode(true));} catch(e) {};
    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("display_type").cloneNode(true));} catch(e) {};

    Why have methods when you can just copy-paste the code you need onto each line? And why bother checking such things as if a node exists before trying to do anything with it when you can just catch any exceptions? This is from a 4165 line javascript file of consistently awful code. The block above is a small sample but there were perhaps three times as many lines just like those where only the name of the child node changes. Another function that could have been somewhat improved had the programmer taken a minute to use an array and a loop rather than his copy-paste approach to everything:

    function displayButtonsBlocExistForCell(sCell)
    //----------------------------
    {
    if(sCell=="A1")
    {
    disableAllButtons()
    }
    else
    {
    if(sCell.substring(0,1)=="A"||isRow1(sCell))
    {
    disableControlButton("btnBodyColumn");
    disableControlButton("btnBodyLine");
    disableControlButton("btnBodyText");
    enableControlButton("btnBodyModify");
    disableControlButton("tdAddNewDocLink1");
    disableControlButton("tdAddNewDocLink2");
    disableControlButton("tdAddComment");
    disableControlButton("tdDelComment");

    G P C P V 8 Replies Last reply
    0
    • D dojohansen

      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("block_name").cloneNode(true)); } catch(e) {};
      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("block_type").cloneNode(true)); } catch(e) {};
      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("title").cloneNode(true)); } catch(e) {};
      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("list_id").cloneNode(true)); } catch(e) {};
      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("format_number").cloneNode(true));} catch(e) {};
      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("format_force").cloneNode(true));} catch(e) {};
      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("visible").cloneNode(true));} catch(e) {};
      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("titre").cloneNode(true));} catch(e) {};
      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_width").cloneNode(true));} catch(e) {};
      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_sens").cloneNode(true));} catch(e) {};
      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_data_type").cloneNode(true));} catch(e) {};
      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("locked").cloneNode(true));} catch(e) {};
      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("display_type").cloneNode(true));} catch(e) {};

      Why have methods when you can just copy-paste the code you need onto each line? And why bother checking such things as if a node exists before trying to do anything with it when you can just catch any exceptions? This is from a 4165 line javascript file of consistently awful code. The block above is a small sample but there were perhaps three times as many lines just like those where only the name of the child node changes. Another function that could have been somewhat improved had the programmer taken a minute to use an array and a loop rather than his copy-paste approach to everything:

      function displayButtonsBlocExistForCell(sCell)
      //----------------------------
      {
      if(sCell=="A1")
      {
      disableAllButtons()
      }
      else
      {
      if(sCell.substring(0,1)=="A"||isRow1(sCell))
      {
      disableControlButton("btnBodyColumn");
      disableControlButton("btnBodyLine");
      disableControlButton("btnBodyText");
      enableControlButton("btnBodyModify");
      disableControlButton("tdAddNewDocLink1");
      disableControlButton("tdAddNewDocLink2");
      disableControlButton("tdAddComment");
      disableControlButton("tdDelComment");

      G Offline
      G Offline
      geoffs
      wrote on last edited by
      #2

      Nice, very nice... :sigh: My apologies if this is the code that you are currently trying to deal with (and it does sound like that is the case). As for me, I'm feeling kind of happy right now because I am in the midst of starting up a new project that will be all new development so I won't have to be dealing with this kind of nonsense. If I'm lucky, development will be controlled enough that none of this will crop in to the code base either (I'm probably not that lucky).

      D 1 Reply Last reply
      0
      • G geoffs

        Nice, very nice... :sigh: My apologies if this is the code that you are currently trying to deal with (and it does sound like that is the case). As for me, I'm feeling kind of happy right now because I am in the midst of starting up a new project that will be all new development so I won't have to be dealing with this kind of nonsense. If I'm lucky, development will be controlled enough that none of this will crop in to the code base either (I'm probably not that lucky).

        D Offline
        D Offline
        dojohansen
        wrote on last edited by
        #3

        I think these came from using external consultants and no peer review to be honest. The only people evaluating anything the consultants did were non-techies so only new buttons in the UI, more pages, more lines of code, and ridiculously simplistic metrics like that were actually being observed. Hence we had effectively set up a system that was basically a trap, for ourselves! I want to point out I was not a part of this team at that time though...

        G G 2 Replies Last reply
        0
        • D dojohansen

          I think these came from using external consultants and no peer review to be honest. The only people evaluating anything the consultants did were non-techies so only new buttons in the UI, more pages, more lines of code, and ridiculously simplistic metrics like that were actually being observed. Hence we had effectively set up a system that was basically a trap, for ourselves! I want to point out I was not a part of this team at that time though...

          G Offline
          G Offline
          geoffs
          wrote on last edited by
          #4

          dojohansen wrote:

          I want to point out I was not a part of this team at that time though...

          ;) That was also my excuse for the code I'd been involved in for the last two years. It's still embarrassing when someone looks at the code for the first time, or notices the bugs in the code in runtime situations, and gives those not so nice glances in the direction of the current developers. It seems like the sins of those who originally wrote the stuff end up becoming the sins of those currently working in it - guilt by association.

          B 1 Reply Last reply
          0
          • D dojohansen

            try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("block_name").cloneNode(true)); } catch(e) {};
            try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("block_type").cloneNode(true)); } catch(e) {};
            try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("title").cloneNode(true)); } catch(e) {};
            try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("list_id").cloneNode(true)); } catch(e) {};
            try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("format_number").cloneNode(true));} catch(e) {};
            try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("format_force").cloneNode(true));} catch(e) {};
            try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("visible").cloneNode(true));} catch(e) {};
            try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("titre").cloneNode(true));} catch(e) {};
            try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_width").cloneNode(true));} catch(e) {};
            try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_sens").cloneNode(true));} catch(e) {};
            try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_data_type").cloneNode(true));} catch(e) {};
            try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("locked").cloneNode(true));} catch(e) {};
            try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("display_type").cloneNode(true));} catch(e) {};

            Why have methods when you can just copy-paste the code you need onto each line? And why bother checking such things as if a node exists before trying to do anything with it when you can just catch any exceptions? This is from a 4165 line javascript file of consistently awful code. The block above is a small sample but there were perhaps three times as many lines just like those where only the name of the child node changes. Another function that could have been somewhat improved had the programmer taken a minute to use an array and a loop rather than his copy-paste approach to everything:

            function displayButtonsBlocExistForCell(sCell)
            //----------------------------
            {
            if(sCell=="A1")
            {
            disableAllButtons()
            }
            else
            {
            if(sCell.substring(0,1)=="A"||isRow1(sCell))
            {
            disableControlButton("btnBodyColumn");
            disableControlButton("btnBodyLine");
            disableControlButton("btnBodyText");
            enableControlButton("btnBodyModify");
            disableControlButton("tdAddNewDocLink1");
            disableControlButton("tdAddNewDocLink2");
            disableControlButton("tdAddComment");
            disableControlButton("tdDelComment");

            P Offline
            P Offline
            Paul Conrad
            wrote on last edited by
            #5

            That is just hideous :wtf:

            "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

            1 Reply Last reply
            0
            • D dojohansen

              try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("block_name").cloneNode(true)); } catch(e) {};
              try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("block_type").cloneNode(true)); } catch(e) {};
              try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("title").cloneNode(true)); } catch(e) {};
              try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("list_id").cloneNode(true)); } catch(e) {};
              try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("format_number").cloneNode(true));} catch(e) {};
              try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("format_force").cloneNode(true));} catch(e) {};
              try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("visible").cloneNode(true));} catch(e) {};
              try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("titre").cloneNode(true));} catch(e) {};
              try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_width").cloneNode(true));} catch(e) {};
              try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_sens").cloneNode(true));} catch(e) {};
              try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_data_type").cloneNode(true));} catch(e) {};
              try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("locked").cloneNode(true));} catch(e) {};
              try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("display_type").cloneNode(true));} catch(e) {};

              Why have methods when you can just copy-paste the code you need onto each line? And why bother checking such things as if a node exists before trying to do anything with it when you can just catch any exceptions? This is from a 4165 line javascript file of consistently awful code. The block above is a small sample but there were perhaps three times as many lines just like those where only the name of the child node changes. Another function that could have been somewhat improved had the programmer taken a minute to use an array and a loop rather than his copy-paste approach to everything:

              function displayButtonsBlocExistForCell(sCell)
              //----------------------------
              {
              if(sCell=="A1")
              {
              disableAllButtons()
              }
              else
              {
              if(sCell.substring(0,1)=="A"||isRow1(sCell))
              {
              disableControlButton("btnBodyColumn");
              disableControlButton("btnBodyLine");
              disableControlButton("btnBodyText");
              enableControlButton("btnBodyModify");
              disableControlButton("tdAddNewDocLink1");
              disableControlButton("tdAddNewDocLink2");
              disableControlButton("tdAddComment");
              disableControlButton("tdDelComment");

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              Yes. :omg:

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              1 Reply Last reply
              0
              • D dojohansen

                I think these came from using external consultants and no peer review to be honest. The only people evaluating anything the consultants did were non-techies so only new buttons in the UI, more pages, more lines of code, and ridiculously simplistic metrics like that were actually being observed. Hence we had effectively set up a system that was basically a trap, for ourselves! I want to point out I was not a part of this team at that time though...

                G Offline
                G Offline
                GibbleCH
                wrote on last edited by
                #7

                More lines of code is a bad thing in my mind. The fewer, the better if it's not sacrificing readability, performance, or functionality...which it rarely does.

                1 Reply Last reply
                0
                • G geoffs

                  dojohansen wrote:

                  I want to point out I was not a part of this team at that time though...

                  ;) That was also my excuse for the code I'd been involved in for the last two years. It's still embarrassing when someone looks at the code for the first time, or notices the bugs in the code in runtime situations, and gives those not so nice glances in the direction of the current developers. It seems like the sins of those who originally wrote the stuff end up becoming the sins of those currently working in it - guilt by association.

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

                  Yes, the current developers always get the heat for things that may have been done years before they even started working at the company. Such is life :sigh:

                  C 1 Reply Last reply
                  0
                  • D dojohansen

                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("block_name").cloneNode(true)); } catch(e) {};
                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("block_type").cloneNode(true)); } catch(e) {};
                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("title").cloneNode(true)); } catch(e) {};
                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("list_id").cloneNode(true)); } catch(e) {};
                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("format_number").cloneNode(true));} catch(e) {};
                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("format_force").cloneNode(true));} catch(e) {};
                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("visible").cloneNode(true));} catch(e) {};
                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("titre").cloneNode(true));} catch(e) {};
                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_width").cloneNode(true));} catch(e) {};
                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_sens").cloneNode(true));} catch(e) {};
                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_data_type").cloneNode(true));} catch(e) {};
                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("locked").cloneNode(true));} catch(e) {};
                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("display_type").cloneNode(true));} catch(e) {};

                    Why have methods when you can just copy-paste the code you need onto each line? And why bother checking such things as if a node exists before trying to do anything with it when you can just catch any exceptions? This is from a 4165 line javascript file of consistently awful code. The block above is a small sample but there were perhaps three times as many lines just like those where only the name of the child node changes. Another function that could have been somewhat improved had the programmer taken a minute to use an array and a loop rather than his copy-paste approach to everything:

                    function displayButtonsBlocExistForCell(sCell)
                    //----------------------------
                    {
                    if(sCell=="A1")
                    {
                    disableAllButtons()
                    }
                    else
                    {
                    if(sCell.substring(0,1)=="A"||isRow1(sCell))
                    {
                    disableControlButton("btnBodyColumn");
                    disableControlButton("btnBodyLine");
                    disableControlButton("btnBodyText");
                    enableControlButton("btnBodyModify");
                    disableControlButton("tdAddNewDocLink1");
                    disableControlButton("tdAddNewDocLink2");
                    disableControlButton("tdAddComment");
                    disableControlButton("tdDelComment");

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #9

                    dojohansen wrote:

                    the additional semi-colons

                    I used to do that with Pascal, so I could count them to know how many statements were in the program.

                    D 1 Reply Last reply
                    0
                    • D dojohansen

                      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("block_name").cloneNode(true)); } catch(e) {};
                      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("block_type").cloneNode(true)); } catch(e) {};
                      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("title").cloneNode(true)); } catch(e) {};
                      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("list_id").cloneNode(true)); } catch(e) {};
                      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("format_number").cloneNode(true));} catch(e) {};
                      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("format_force").cloneNode(true));} catch(e) {};
                      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("visible").cloneNode(true));} catch(e) {};
                      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("titre").cloneNode(true));} catch(e) {};
                      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_width").cloneNode(true));} catch(e) {};
                      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_sens").cloneNode(true));} catch(e) {};
                      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_data_type").cloneNode(true));} catch(e) {};
                      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("locked").cloneNode(true));} catch(e) {};
                      try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("display_type").cloneNode(true));} catch(e) {};

                      Why have methods when you can just copy-paste the code you need onto each line? And why bother checking such things as if a node exists before trying to do anything with it when you can just catch any exceptions? This is from a 4165 line javascript file of consistently awful code. The block above is a small sample but there were perhaps three times as many lines just like those where only the name of the child node changes. Another function that could have been somewhat improved had the programmer taken a minute to use an array and a loop rather than his copy-paste approach to everything:

                      function displayButtonsBlocExistForCell(sCell)
                      //----------------------------
                      {
                      if(sCell=="A1")
                      {
                      disableAllButtons()
                      }
                      else
                      {
                      if(sCell.substring(0,1)=="A"||isRow1(sCell))
                      {
                      disableControlButton("btnBodyColumn");
                      disableControlButton("btnBodyLine");
                      disableControlButton("btnBodyText");
                      enableControlButton("btnBodyModify");
                      disableControlButton("tdAddNewDocLink1");
                      disableControlButton("tdAddNewDocLink2");
                      disableControlButton("tdAddComment");
                      disableControlButton("tdDelComment");

                      V Offline
                      V Offline
                      VentsyV
                      wrote on last edited by
                      #10

                      Whats wrong with the semi-colons; I put semi-colons everywhere; It is a C/C++ thing;

                      L P 2 Replies Last reply
                      0
                      • V VentsyV

                        Whats wrong with the semi-colons; I put semi-colons everywhere; It is a C/C++ thing;

                        L Offline
                        L Offline
                        Lutoslaw
                        wrote on last edited by
                        #11

                        VentsyV wrote:

                        Whats wrong with the semi-colons; I put semi-colons everywhere; It is a C/C++ thing;

                        Yeah semicolons are cool; aren't they;

                        Greetings - Gajatko; Portable.NET is part of DotGNU; a project to build a complete Free Software replacement for .NET ; a system that truly belongs to the developers;

                        1 Reply Last reply
                        0
                        • V VentsyV

                          Whats wrong with the semi-colons; I put semi-colons everywhere; It is a C/C++ thing;

                          P Offline
                          P Offline
                          Paul Conrad
                          wrote on last edited by
                          #12

                          Perhaps it was more about all the try/catches with nothing really happening in the catch block.

                          "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                          D 1 Reply Last reply
                          0
                          • P PIEBALDconsult

                            dojohansen wrote:

                            the additional semi-colons

                            I used to do that with Pascal, so I could count them to know how many statements were in the program.

                            D Offline
                            D Offline
                            dojohansen
                            wrote on last edited by
                            #13

                            But here the semi-colon adds an empty statement! This is a javascript function block with two statements:

                            function f()
                            {
                            a = 5;
                            ++i;
                            }

                            The function itself is a declaration, not a statement, and adding a semicolon merely makes it a block with two statements followed by an empty statement. Admittedly the difference between a declaration and a statement is a bit fuzzy in this case, since in js a function declaration is equivalent to an assignment statement, like this:

                            var f = function()
                            {
                            a = 5;
                            ++i;
                            };

                            In which case it's correct to include the semicolon (because it ends a statement in this case). Anyway, my real problem is the insane amount of reduncancy in the code. I declare war on copy-paste "programmers" the world over!

                            C 1 Reply Last reply
                            0
                            • P Paul Conrad

                              Perhaps it was more about all the try/catches with nothing really happening in the catch block.

                              "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                              D Offline
                              D Offline
                              dojohansen
                              wrote on last edited by
                              #14

                              He was trying to copy a subset of xml data from one document to another (how this can be useful beats me unless you unload the document containing the superset of data, but anyway that's what he tried to do) but the data would not have the same nodes in all cases. Apparently upon discovering this he figured he'd just wrap the code copying each node into a try-catch so it continues if a node doesn't exist. This is a lazy approach and a coding horror in my book. First, the cost of catching exceptions instead of checking if nodes exist before trying to clone them is *huge*. Second, in most cases the try block can fail for other reasons than the one which "is ok" and means you should just go on. This project is plagued by that particular problem, people catch an exception because they want the program to "keep working" but of course all it does is make it fail in strange ways while leaving no useful debugging information. It's worse when they do this server-side since the client-side exceptions aren't so rich on information anyway but the principle is the same. My real gripe however is the code redundancy. If you intend to perform the same operation 20 times over you should use the same implementation 20 times, so it's possible to change the darn thing without getting bored to death. I also think that if the operation is of a fairly generic nature, say, copying a subset of xml nodes from one document to another, you should separate the logic from any particular bits of the systems such as, say, a specific web page in a complex application. The guy is now Chef de projet développements (not for my team thankfully) and continues to wreak havoc at undiminished speed. An example of what he might have written instead:

                              function copyChildNodes(srcNode, destNode, nodeList, ignoreMissingNodes)
                              {
                              for (var i=0; i < nodeList.length; i++)
                              {
                              var node = srcNode.selectSingleNode(nodeList[i]);
                              if (!node)
                              {
                              if (ignoreMissingNodes)
                              continue;
                              else
                              throw {message: "No child node with name '" + nodeList[i] + "' exists in the source node."};
                              }
                              destNode.appendChild(node.cloneNode(true));
                              }
                              }

                              Put that in one of our several script files intended for code a little bit more general than the page-specfic stuff and put this in the page (instead of the twenty lines doing the same thing):

                              var nodes = ["block_name", "block_type", "title", "list_id", "you", "get", "the", "point"];
                              copyChildNodes(o

                              D 1 Reply Last reply
                              0
                              • D dojohansen

                                try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("block_name").cloneNode(true)); } catch(e) {};
                                try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("block_type").cloneNode(true)); } catch(e) {};
                                try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("title").cloneNode(true)); } catch(e) {};
                                try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("list_id").cloneNode(true)); } catch(e) {};
                                try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("format_number").cloneNode(true));} catch(e) {};
                                try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("format_force").cloneNode(true));} catch(e) {};
                                try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("visible").cloneNode(true));} catch(e) {};
                                try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("titre").cloneNode(true));} catch(e) {};
                                try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_width").cloneNode(true));} catch(e) {};
                                try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_sens").cloneNode(true));} catch(e) {};
                                try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_data_type").cloneNode(true));} catch(e) {};
                                try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("locked").cloneNode(true));} catch(e) {};
                                try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("display_type").cloneNode(true));} catch(e) {};

                                Why have methods when you can just copy-paste the code you need onto each line? And why bother checking such things as if a node exists before trying to do anything with it when you can just catch any exceptions? This is from a 4165 line javascript file of consistently awful code. The block above is a small sample but there were perhaps three times as many lines just like those where only the name of the child node changes. Another function that could have been somewhat improved had the programmer taken a minute to use an array and a loop rather than his copy-paste approach to everything:

                                function displayButtonsBlocExistForCell(sCell)
                                //----------------------------
                                {
                                if(sCell=="A1")
                                {
                                disableAllButtons()
                                }
                                else
                                {
                                if(sCell.substring(0,1)=="A"||isRow1(sCell))
                                {
                                disableControlButton("btnBodyColumn");
                                disableControlButton("btnBodyLine");
                                disableControlButton("btnBodyText");
                                enableControlButton("btnBodyModify");
                                disableControlButton("tdAddNewDocLink1");
                                disableControlButton("tdAddNewDocLink2");
                                disableControlButton("tdAddComment");
                                disableControlButton("tdDelComment");

                                R Offline
                                R Offline
                                rcollina
                                wrote on last edited by
                                #15

                                Seen something very similar from a guy who sells the source code of his application for more than 2000 dollars. He said that using try catch blocks like it's going out of fashion is "covering every base". ...the horror. :(

                                1 Reply Last reply
                                0
                                • D dojohansen

                                  He was trying to copy a subset of xml data from one document to another (how this can be useful beats me unless you unload the document containing the superset of data, but anyway that's what he tried to do) but the data would not have the same nodes in all cases. Apparently upon discovering this he figured he'd just wrap the code copying each node into a try-catch so it continues if a node doesn't exist. This is a lazy approach and a coding horror in my book. First, the cost of catching exceptions instead of checking if nodes exist before trying to clone them is *huge*. Second, in most cases the try block can fail for other reasons than the one which "is ok" and means you should just go on. This project is plagued by that particular problem, people catch an exception because they want the program to "keep working" but of course all it does is make it fail in strange ways while leaving no useful debugging information. It's worse when they do this server-side since the client-side exceptions aren't so rich on information anyway but the principle is the same. My real gripe however is the code redundancy. If you intend to perform the same operation 20 times over you should use the same implementation 20 times, so it's possible to change the darn thing without getting bored to death. I also think that if the operation is of a fairly generic nature, say, copying a subset of xml nodes from one document to another, you should separate the logic from any particular bits of the systems such as, say, a specific web page in a complex application. The guy is now Chef de projet développements (not for my team thankfully) and continues to wreak havoc at undiminished speed. An example of what he might have written instead:

                                  function copyChildNodes(srcNode, destNode, nodeList, ignoreMissingNodes)
                                  {
                                  for (var i=0; i < nodeList.length; i++)
                                  {
                                  var node = srcNode.selectSingleNode(nodeList[i]);
                                  if (!node)
                                  {
                                  if (ignoreMissingNodes)
                                  continue;
                                  else
                                  throw {message: "No child node with name '" + nodeList[i] + "' exists in the source node."};
                                  }
                                  destNode.appendChild(node.cloneNode(true));
                                  }
                                  }

                                  Put that in one of our several script files intended for code a little bit more general than the page-specfic stuff and put this in the page (instead of the twenty lines doing the same thing):

                                  var nodes = ["block_name", "block_type", "title", "list_id", "you", "get", "the", "point"];
                                  copyChildNodes(o

                                  D Offline
                                  D Offline
                                  Dan Neely
                                  wrote on last edited by
                                  #16

                                  dojohansen wrote:

                                  My real gripe however is the code redundancy. If you intend to perform the same operation 20 times over you should use the same implementation 20 times, so it's possible to change the darn thing without getting bored to death.

                                  What are you talking about, that just means you get to have fun writing an overly complex regex to update the code with. :rolleyes:

                                  Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                                  1 Reply Last reply
                                  0
                                  • D dojohansen

                                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("block_name").cloneNode(true)); } catch(e) {};
                                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("block_type").cloneNode(true)); } catch(e) {};
                                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("title").cloneNode(true)); } catch(e) {};
                                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("list_id").cloneNode(true)); } catch(e) {};
                                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("format_number").cloneNode(true));} catch(e) {};
                                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("format_force").cloneNode(true));} catch(e) {};
                                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("visible").cloneNode(true));} catch(e) {};
                                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("titre").cloneNode(true));} catch(e) {};
                                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_width").cloneNode(true));} catch(e) {};
                                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_sens").cloneNode(true));} catch(e) {};
                                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("bloc_data_type").cloneNode(true));} catch(e) {};
                                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("locked").cloneNode(true));} catch(e) {};
                                    try { oXMLRecord.appendChild(oXMLBlock.selectSingleNode("display_type").cloneNode(true));} catch(e) {};

                                    Why have methods when you can just copy-paste the code you need onto each line? And why bother checking such things as if a node exists before trying to do anything with it when you can just catch any exceptions? This is from a 4165 line javascript file of consistently awful code. The block above is a small sample but there were perhaps three times as many lines just like those where only the name of the child node changes. Another function that could have been somewhat improved had the programmer taken a minute to use an array and a loop rather than his copy-paste approach to everything:

                                    function displayButtonsBlocExistForCell(sCell)
                                    //----------------------------
                                    {
                                    if(sCell=="A1")
                                    {
                                    disableAllButtons()
                                    }
                                    else
                                    {
                                    if(sCell.substring(0,1)=="A"||isRow1(sCell))
                                    {
                                    disableControlButton("btnBodyColumn");
                                    disableControlButton("btnBodyLine");
                                    disableControlButton("btnBodyText");
                                    enableControlButton("btnBodyModify");
                                    disableControlButton("tdAddNewDocLink1");
                                    disableControlButton("tdAddNewDocLink2");
                                    disableControlButton("tdAddComment");
                                    disableControlButton("tdDelComment");

                                    T Offline
                                    T Offline
                                    Tom1
                                    wrote on last edited by
                                    #17

                                    Sadly, had a boss one time that changed my code from using an array and a loop_index to code that looks like the example. Perhaps we were being paid per line of source code generated?

                                    1 Reply Last reply
                                    0
                                    • B BillW33

                                      Yes, the current developers always get the heat for things that may have been done years before they even started working at the company. Such is life :sigh:

                                      C Offline
                                      C Offline
                                      cpkilekofp
                                      wrote on last edited by
                                      #18

                                      CIDev wrote:

                                      Yes, the current developers always get the heat for things that may have been done years before they even started working at the company. Such is life

                                      Can anyone say "Refactoring"? I've spent a good deal of my career refactoring bad code, even when I had to do it on the sly to keep "if it ain't broke, don't fix it" bosses from burying me in manure. If it's bad code, it IS broken and needs to be fixed. If your life sucks, you're working by the wrong set of rules.

                                      B 1 Reply Last reply
                                      0
                                      • D dojohansen

                                        But here the semi-colon adds an empty statement! This is a javascript function block with two statements:

                                        function f()
                                        {
                                        a = 5;
                                        ++i;
                                        }

                                        The function itself is a declaration, not a statement, and adding a semicolon merely makes it a block with two statements followed by an empty statement. Admittedly the difference between a declaration and a statement is a bit fuzzy in this case, since in js a function declaration is equivalent to an assignment statement, like this:

                                        var f = function()
                                        {
                                        a = 5;
                                        ++i;
                                        };

                                        In which case it's correct to include the semicolon (because it ends a statement in this case). Anyway, my real problem is the insane amount of reduncancy in the code. I declare war on copy-paste "programmers" the world over!

                                        C Offline
                                        C Offline
                                        cpkilekofp
                                        wrote on last edited by
                                        #19

                                        dojohansen wrote:

                                        I declare war on copy-paste "programmers" the world over!

                                        To the death!!! :laugh:...alright, To the death or reform!! (I've been guilty of this occasionally as well, especially when I was in a screaming hurry...but it's VERY rare that I've left copy-and-paste stuff in my code longer than the first moment I could go back and revise it).

                                        1 Reply Last reply
                                        0
                                        • C cpkilekofp

                                          CIDev wrote:

                                          Yes, the current developers always get the heat for things that may have been done years before they even started working at the company. Such is life

                                          Can anyone say "Refactoring"? I've spent a good deal of my career refactoring bad code, even when I had to do it on the sly to keep "if it ain't broke, don't fix it" bosses from burying me in manure. If it's bad code, it IS broken and needs to be fixed. If your life sucks, you're working by the wrong set of rules.

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

                                          I normally "tweak" or just plain replace old code that may work, but is really bad code. I don't always have enough time to replace as much bad code as I would like, but I do it whenever possible. Bill W

                                          C 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