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. Make sure this value is returned...

Make sure this value is returned...

Scheduled Pinned Locked Moved The Weird and The Wonderful
linux
9 Posts 5 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.
  • C Offline
    C Offline
    cmger
    wrote on last edited by
    #1

    Hi all, I was already reading this forum when it was still called the "Hall of shame". I've got a product to maintain that was created by a developer who is no longer working for us. Even though I've already seen plenty of "hall of shame worthy" code there, I've have never posted it here, because it would have been my first post on CP ever and I thought it is a bad idea to say hello to a community while bashing an ex colleague. However, I came across a piece of code that I can't keep for myself and so I'll do what I didn't want to do and bash in my first post: At the end of a long method I found this one:

    try
    {
    return true;
    }
    catch (Exception)
    {
    return false;
    }

    Cheers, cmger

    B 1 Reply Last reply
    0
    • C cmger

      Hi all, I was already reading this forum when it was still called the "Hall of shame". I've got a product to maintain that was created by a developer who is no longer working for us. Even though I've already seen plenty of "hall of shame worthy" code there, I've have never posted it here, because it would have been my first post on CP ever and I thought it is a bad idea to say hello to a community while bashing an ex colleague. However, I came across a piece of code that I can't keep for myself and so I'll do what I didn't want to do and bash in my first post: At the end of a long method I found this one:

      try
      {
      return true;
      }
      catch (Exception)
      {
      return false;
      }

      Cheers, cmger

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

      Welcome to posting on CP. :) I hope that there used to be more code in the try catch that would give it a reason to be there. Even if there used to be code that justified the try, when that code was removed the try/catch should have also been removed. This is another fine example of code that might work, but really isn't good code, hence my sig. :)

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

      C G R 3 Replies Last reply
      0
      • B BillW33

        Welcome to posting on CP. :) I hope that there used to be more code in the try catch that would give it a reason to be there. Even if there used to be code that justified the try, when that code was removed the try/catch should have also been removed. This is another fine example of code that might work, but really isn't good code, hence my sig. :)

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

        C Offline
        C Offline
        cmger
        wrote on last edited by
        #3

        Thanks for the welcome! :-) Nope, there was never anything more in there. At least as far as I can tell from the source control system. I found out that there is only one place where the method is used and there the return value is just ignored. I re-factored the method to return void an removed the block completely. Now there is only the code that preceded the try catch.

        A B 2 Replies Last reply
        0
        • C cmger

          Thanks for the welcome! :-) Nope, there was never anything more in there. At least as far as I can tell from the source control system. I found out that there is only one place where the method is used and there the return value is just ignored. I re-factored the method to return void an removed the block completely. Now there is only the code that preceded the try catch.

          A Offline
          A Offline
          Andrei Straut
          wrote on last edited by
          #4

          Maybe it was some kind of skeleton for logic to be inserted in the try-catch block later? However, it should've been preceded by a comment at least.

          cmger wrote:

          I found out that there is only one place where the method is used and there the return value is just ignored.

          Rejoice, for you got away easily! :laugh: :laugh: It could've been a lot worse ;)

          Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

          1 Reply Last reply
          0
          • C cmger

            Thanks for the welcome! :-) Nope, there was never anything more in there. At least as far as I can tell from the source control system. I found out that there is only one place where the method is used and there the return value is just ignored. I re-factored the method to return void an removed the block completely. Now there is only the code that preceded the try catch.

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

            I am not surprised that there was never any useful code there, just disappointed. :sigh: I really hate it when programmers return a value that serves no purpose. :mad:

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

            C 1 Reply Last reply
            0
            • B BillW33

              I am not surprised that there was never any useful code there, just disappointed. :sigh: I really hate it when programmers return a value that serves no purpose. :mad:

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

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

              Oh, then you would really love the code base where the above stems from,... Not! :laugh:

              B 1 Reply Last reply
              0
              • B BillW33

                Welcome to posting on CP. :) I hope that there used to be more code in the try catch that would give it a reason to be there. Even if there used to be code that justified the try, when that code was removed the try/catch should have also been removed. This is another fine example of code that might work, but really isn't good code, hence my sig. :)

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

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

                Looks more like a stub - that was never filled out.

                1 Reply Last reply
                0
                • C cmger

                  Oh, then you would really love the code base where the above stems from,... Not! :laugh:

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

                  cmger Wrote:

                  Oh, then you would really love the code base where the above stems from,... Not!

                  Sounds like you have a lot more potential entries for this forum. :sigh:

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

                  1 Reply Last reply
                  0
                  • B BillW33

                    Welcome to posting on CP. :) I hope that there used to be more code in the try catch that would give it a reason to be there. Even if there used to be code that justified the try, when that code was removed the try/catch should have also been removed. This is another fine example of code that might work, but really isn't good code, hence my sig. :)

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

                    R Offline
                    R Offline
                    Renzo Ciafardone
                    wrote on last edited by
                    #9

                    My guess is that this was "skeleton" code that the coder copy pasted but forgot to fill.

                    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