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. It's a jungle in there

It's a jungle in there

Scheduled Pinned Locked Moved The Weird and The Wonderful
24 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.
  • G Offline
    G Offline
    GibbleCH
    wrote on last edited by
    #1

    I was refactoring a horribly written app. Tons of duplicated code. Crazy amounts of dead code (~30-50%). And my personal favourite, was a method that went something like this.

    public void Some_Method()
    {
    try
    {

    }
    catch (Exception x)
    {
        LogException(x);
    }
    

    }

    Fortunately, or not, this method was never called...but I sure am glad the catch block was there....just in case that empty try block failed.

    L S R Sander RosselS B 8 Replies Last reply
    0
    • G GibbleCH

      I was refactoring a horribly written app. Tons of duplicated code. Crazy amounts of dead code (~30-50%). And my personal favourite, was a method that went something like this.

      public void Some_Method()
      {
      try
      {

      }
      catch (Exception x)
      {
          LogException(x);
      }
      

      }

      Fortunately, or not, this method was never called...but I sure am glad the catch block was there....just in case that empty try block failed.

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

      I would call it a masterpiece. :laugh: :laugh: :laugh:

      1 Reply Last reply
      0
      • G GibbleCH

        I was refactoring a horribly written app. Tons of duplicated code. Crazy amounts of dead code (~30-50%). And my personal favourite, was a method that went something like this.

        public void Some_Method()
        {
        try
        {

        }
        catch (Exception x)
        {
            LogException(x);
        }
        

        }

        Fortunately, or not, this method was never called...but I sure am glad the catch block was there....just in case that empty try block failed.

        S Offline
        S Offline
        StM0n
        wrote on last edited by
        #3

        The memorial of the never-written-code... with exception-handling

        (yes|no|maybe)*

        1 Reply Last reply
        0
        • G GibbleCH

          I was refactoring a horribly written app. Tons of duplicated code. Crazy amounts of dead code (~30-50%). And my personal favourite, was a method that went something like this.

          public void Some_Method()
          {
          try
          {

          }
          catch (Exception x)
          {
              LogException(x);
          }
          

          }

          Fortunately, or not, this method was never called...but I sure am glad the catch block was there....just in case that empty try block failed.

          R Offline
          R Offline
          Reiss
          wrote on last edited by
          #4

          As a consultant I share your pain.

          GibbleCH wrote:

          Tons of duplicated code. Crazy amounts of dead code (~30-50%)

          sounds like it would be quicker to re-write

          G 1 Reply Last reply
          0
          • R Reiss

            As a consultant I share your pain.

            GibbleCH wrote:

            Tons of duplicated code. Crazy amounts of dead code (~30-50%)

            sounds like it would be quicker to re-write

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

            Ultimately that was the result. But using lots of unit tests and refactoring to do so. Less error prone, and I was able to ensure functionality remained consistent where it was correct. And some bits of the app did work...

            1 Reply Last reply
            0
            • G GibbleCH

              I was refactoring a horribly written app. Tons of duplicated code. Crazy amounts of dead code (~30-50%). And my personal favourite, was a method that went something like this.

              public void Some_Method()
              {
              try
              {

              }
              catch (Exception x)
              {
                  LogException(x);
              }
              

              }

              Fortunately, or not, this method was never called...but I sure am glad the catch block was there....just in case that empty try block failed.

              Sander RosselS Offline
              Sander RosselS Offline
              Sander Rossel
              wrote on last edited by
              #6

              I see the opposite way to often too...

              Private Sub DoSomething
              Try
              ' Lots of badly written code inspired by VB6 and earlier here.
              Catch ex As Exception

              End Try

              A Try Catch block with no code does no harm, this however... :sigh: Perhaps the empty Catch is also VB6 inspired... OnErrorResumeNext :(

              It's an OO world.

              F G 2 Replies Last reply
              0
              • G GibbleCH

                I was refactoring a horribly written app. Tons of duplicated code. Crazy amounts of dead code (~30-50%). And my personal favourite, was a method that went something like this.

                public void Some_Method()
                {
                try
                {

                }
                catch (Exception x)
                {
                    LogException(x);
                }
                

                }

                Fortunately, or not, this method was never called...but I sure am glad the catch block was there....just in case that empty try block failed.

                B Offline
                B Offline
                Bernhard Hiller
                wrote on last edited by
                #7

                I think the guy created a function body to copy for other functions. That would save him writing the exception handling block over and over again when a new function is added. No coding horror, though it might look like one at first view.

                B A U 3 Replies Last reply
                0
                • B Bernhard Hiller

                  I think the guy created a function body to copy for other functions. That would save him writing the exception handling block over and over again when a new function is added. No coding horror, though it might look like one at first view.

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

                  Copying the exception handling over and over again would be a coding horror anyway. The exception should generally be caught in only a few places in the top tier.

                  1 Reply Last reply
                  0
                  • B Bernhard Hiller

                    I think the guy created a function body to copy for other functions. That would save him writing the exception handling block over and over again when a new function is added. No coding horror, though it might look like one at first view.

                    A Offline
                    A Offline
                    Amar Chaudhary
                    wrote on last edited by
                    #9

                    try [enter] or try[tab][tab] even if you have already written the code- select code and [ctrl][k][s] try [enter]

                    My Startup!!!!
                    Profile@Elance - feedback available too

                    1 Reply Last reply
                    0
                    • Sander RosselS Sander Rossel

                      I see the opposite way to often too...

                      Private Sub DoSomething
                      Try
                      ' Lots of badly written code inspired by VB6 and earlier here.
                      Catch ex As Exception

                      End Try

                      A Try Catch block with no code does no harm, this however... :sigh: Perhaps the empty Catch is also VB6 inspired... OnErrorResumeNext :(

                      It's an OO world.

                      F Offline
                      F Offline
                      Fabio Franco
                      wrote on last edited by
                      #10

                      Naerling wrote:

                      Perhaps the empty Catch is also VB6 inspired... OnErrorResumeNext

                      Is it just me or everytime someone talks about bad code, "VB" shows up? :sigh:

                      "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

                      Sander RosselS C 2 Replies Last reply
                      0
                      • Sander RosselS Sander Rossel

                        I see the opposite way to often too...

                        Private Sub DoSomething
                        Try
                        ' Lots of badly written code inspired by VB6 and earlier here.
                        Catch ex As Exception

                        End Try

                        A Try Catch block with no code does no harm, this however... :sigh: Perhaps the empty Catch is also VB6 inspired... OnErrorResumeNext :(

                        It's an OO world.

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

                        There was tons of that in there too. Along with lots of catch blocks that broke the call stack by throwing a new, useless error message.

                        Sander RosselS 1 Reply Last reply
                        0
                        • G GibbleCH

                          I was refactoring a horribly written app. Tons of duplicated code. Crazy amounts of dead code (~30-50%). And my personal favourite, was a method that went something like this.

                          public void Some_Method()
                          {
                          try
                          {

                          }
                          catch (Exception x)
                          {
                              LogException(x);
                          }
                          

                          }

                          Fortunately, or not, this method was never called...but I sure am glad the catch block was there....just in case that empty try block failed.

                          B Offline
                          B Offline
                          Br Bill
                          wrote on last edited by
                          #12

                          I find it brilliant. 100% bug-free!

                          1 Reply Last reply
                          0
                          • F Fabio Franco

                            Naerling wrote:

                            Perhaps the empty Catch is also VB6 inspired... OnErrorResumeNext

                            Is it just me or everytime someone talks about bad code, "VB" shows up? :sigh:

                            "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

                            Sander RosselS Offline
                            Sander RosselS Offline
                            Sander Rossel
                            wrote on last edited by
                            #13

                            I blame VB 1, 2 and 3. I was a toddler at that time so I wouldn't know, but this is what I heard. VB became object oriented at version 4, but to be backwards compatible MS had to support the non-object oriented style. As a result many VB programmers kept on programming like they always did and still do so today. Why not C#? Because the first C# came at around the same time as VB4 and was object oriented right from the start. On a side note, try to call any PUBLIC member of a Form in VB without having an instance of the Form. It will work, you can call them as if they were Shared (static). I recently found out and was shocked, backwards compatibility with VB1... X| Anyway, I don't really blame VB, I blame the programmers who were not willing to learn object orientism right after VB3 :sigh: Does that sound about right or am I really way off here?

                            It's an OO world.

                            F 1 Reply Last reply
                            0
                            • G GibbleCH

                              There was tons of that in there too. Along with lots of catch blocks that broke the call stack by throwing a new, useless error message.

                              Sander RosselS Offline
                              Sander RosselS Offline
                              Sander Rossel
                              wrote on last edited by
                              #14

                              Or my favourite:

                              Try
                              ' (Lots of) code here.
                              Catch ex As Exception
                              LogError(0, ex.Message, "SomeClass.SomeMethod")
                              End Try

                              Yes, we did not pass the Exception Object to the LogError Method, we provided some parameters as Strings. I still don't know what the first parameter is. It is always 0... "SomeClass.SomeMethod" is not fetched from the Exception Object, but passed as a fixed String. It gets worse, because this piece of code is copied in EVERY Try Catch block (except the empty ones of course). See how copying "SomeClass.SomeMethod" does not work for "SomeClass.OtherMethod"? :) So our logging is often not very reliable. And even if it is (it is not ALL bad) it usually does not say very much because we don't log stacktraces etc. A log that says "Reference not set to an instance of an Object" in a Method with some 100 lines of code is really not very helpful :) Next to that there is a Try Catch block in almost EVERY Method, but NEVER a ReThrow or a MessageBox.Show to the user. What a way to handle Exceptions! :thumbsup: It annoyed me so much I decided to write an article about it :)

                              It's an OO world.

                              1 Reply Last reply
                              0
                              • B Bernhard Hiller

                                I think the guy created a function body to copy for other functions. That would save him writing the exception handling block over and over again when a new function is added. No coding horror, though it might look like one at first view.

                                U Offline
                                U Offline
                                User 7736130
                                wrote on last edited by
                                #15

                                Maybe he didn't know about code snippets....

                                1 Reply Last reply
                                0
                                • Sander RosselS Sander Rossel

                                  I blame VB 1, 2 and 3. I was a toddler at that time so I wouldn't know, but this is what I heard. VB became object oriented at version 4, but to be backwards compatible MS had to support the non-object oriented style. As a result many VB programmers kept on programming like they always did and still do so today. Why not C#? Because the first C# came at around the same time as VB4 and was object oriented right from the start. On a side note, try to call any PUBLIC member of a Form in VB without having an instance of the Form. It will work, you can call them as if they were Shared (static). I recently found out and was shocked, backwards compatibility with VB1... X| Anyway, I don't really blame VB, I blame the programmers who were not willing to learn object orientism right after VB3 :sigh: Does that sound about right or am I really way off here?

                                  It's an OO world.

                                  F Offline
                                  F Offline
                                  Fabio Franco
                                  wrote on last edited by
                                  #16

                                  Naerling wrote:

                                  VB became object oriented at version 4

                                  Not fully, still lacked lots of OO principles, even VB 6 (like something as basic as inheritance).

                                  Naerling wrote:

                                  I blame the programmers who were not willing to learn object orientism right after VB3

                                  I actually seen that in action on VB.Net.

                                  Naerling wrote:

                                  Does that sound about right or am I really way off here?

                                  Yes, it does. But in my opinion that's not the full story and the full story about all the VB infame does not apply to everyone and to all scenarios. But yes, the word VB gives me goose bumps, specially when I learn I have to work with existing code.

                                  "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

                                  Sander RosselS 1 Reply Last reply
                                  0
                                  • F Fabio Franco

                                    Naerling wrote:

                                    VB became object oriented at version 4

                                    Not fully, still lacked lots of OO principles, even VB 6 (like something as basic as inheritance).

                                    Naerling wrote:

                                    I blame the programmers who were not willing to learn object orientism right after VB3

                                    I actually seen that in action on VB.Net.

                                    Naerling wrote:

                                    Does that sound about right or am I really way off here?

                                    Yes, it does. But in my opinion that's not the full story and the full story about all the VB infame does not apply to everyone and to all scenarios. But yes, the word VB gives me goose bumps, specially when I learn I have to work with existing code.

                                    "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

                                    Sander RosselS Offline
                                    Sander RosselS Offline
                                    Sander Rossel
                                    wrote on last edited by
                                    #17

                                    I had to work with lots of existing VB code... Code that goes as far back as being coded in VB6 and imported to .NET (when I started to learn programming there I learned from seeing what NOT to do) :omg: Luckily my hard studies got me to a point where my boss actually lets me write new classes and libraries for every programmer in the company (that's 4 people including me...) to use (and yes, I am one of those VB programmers who DOES know what an Interface (other than GUI) is and how to use it) :D

                                    It's an OO world.

                                    F 1 Reply Last reply
                                    0
                                    • Sander RosselS Sander Rossel

                                      I had to work with lots of existing VB code... Code that goes as far back as being coded in VB6 and imported to .NET (when I started to learn programming there I learned from seeing what NOT to do) :omg: Luckily my hard studies got me to a point where my boss actually lets me write new classes and libraries for every programmer in the company (that's 4 people including me...) to use (and yes, I am one of those VB programmers who DOES know what an Interface (other than GUI) is and how to use it) :D

                                      It's an OO world.

                                      F Offline
                                      F Offline
                                      Fabio Franco
                                      wrote on last edited by
                                      #18

                                      Naerling wrote:

                                      my boss actually lets me write new classes and libraries for every programmer in the company to use

                                      Now, that's really cool. It's a very nice role to have.

                                      Naerling wrote:

                                      and yes, I am one of those VB programmers who DOES know what an Interface (other than GUI) is and how to use it

                                      Some may consider you a mythical character :laugh:

                                      "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

                                      Sander RosselS 1 Reply Last reply
                                      0
                                      • F Fabio Franco

                                        Naerling wrote:

                                        my boss actually lets me write new classes and libraries for every programmer in the company to use

                                        Now, that's really cool. It's a very nice role to have.

                                        Naerling wrote:

                                        and yes, I am one of those VB programmers who DOES know what an Interface (other than GUI) is and how to use it

                                        Some may consider you a mythical character :laugh:

                                        "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

                                        Sander RosselS Offline
                                        Sander RosselS Offline
                                        Sander Rossel
                                        wrote on last edited by
                                        #19

                                        Fabio Franco wrote:

                                        Some may consider you a mythical character

                                        Thanks! :laugh:

                                        It's an OO world.

                                        1 Reply Last reply
                                        0
                                        • G GibbleCH

                                          I was refactoring a horribly written app. Tons of duplicated code. Crazy amounts of dead code (~30-50%). And my personal favourite, was a method that went something like this.

                                          public void Some_Method()
                                          {
                                          try
                                          {

                                          }
                                          catch (Exception x)
                                          {
                                              LogException(x);
                                          }
                                          

                                          }

                                          Fortunately, or not, this method was never called...but I sure am glad the catch block was there....just in case that empty try block failed.

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

                                          I feel your pain. I've just finished going through a similar process. After a while you stop getting annoyed and start laughing. The one that made me laugh most was:

                                          public class OrderName
                                          {
                                          public String getName {
                                          return "Order";
                                          }
                                          }

                                          That was the class in totality. One method that returned a hard coded value. [EDIT] I just found a better one:

                                          for (int i = 1; i < 2; i++) {
                                          //Code was here
                                          }

                                          "You get that on the big jobs."

                                          modified on Sunday, August 14, 2011 10:23 PM

                                          G 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