• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Code review - hilarious code snippets

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    #61
    Originally posted by suityou01 View Post
    unhandled exception
    Oh for ****s flippin' sake. <mod. you meant that didn't you?>

    I'm not suggesting you don't handle the ******* exception. I'm comparing try catch, with an exception raised when an enclosed method fails, to calling a method and checking the result to see if it worked or not.

    Anyway as i said, semantics is key. If the method is returning null because of an error it should be raising an exception. This may well need to be propogated, and propgating a null value up the call stack is error prone and you lose context so you can't write a stack trace etc. If it's returning null because the answer is null then return null.
    While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'

    Comment


      #62
      Originally posted by russell View Post
      Exceptions should only be used for situations that you cannot foresee i.e. A external resource not being available, not for an empty search result from a query, the clue is in the name.
      Exactly. But the reverse is that returning null should only be used to indicate a null result, not to indicate that everything is ****ed because of something that happened or didn't happen 300 lines of code back when you were parseing a configuration file.
      While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'

      Comment


        #63
        Originally posted by russell View Post
        Exceptions should only be used for situations that you cannot foresee i.e. A external resource not being available, not for an empty search result from a query, the clue is in the name.
        Russell, I was simply querying Suity's (in)ability to read rather than the question itself. suity did his usual job of half reading something and making a comment based on his assumption (in this case that doodab suggested a try block with no exception handling).
        merely at clientco for the entertainment

        Comment


          #64
          Originally posted by doodab View Post
          Exactly. But the reverse is that returning null should only be used to indicate a null result, not to indicate that everything is ****ed because of something that happened or didn't happen 300 lines of code back when you were parseing a configuration file.
          Yeah that is true. If you come from a language that has no exceptions then returning null rather than a pointer for eg is valid, then let the caller assert that or handle it.

          Comment


            #65
            Originally posted by doodab View Post
            If it's a valid result then fair enough but if you can't initialize an object properly when the constructor is called throw an exception in the constructor. Don't return normally then expect people to call isValid() on your object, check the result of every method invocation to see if it's null, or even worse just throw unchecked exceptions all over the shop because the object was never initialised properly.

            Especially don't do the latter two when it's even more of your tulipty code that is calling methods on the improperly constructed object.
            That reminds me. Why do so many C/C++ programmers never bother checking error returns?
            Behold the warranty -- the bold print giveth and the fine print taketh away.

            Comment


              #66
              Originally posted by suityou01 View Post
              And again in English
              Well, eek said
              Originally posted by eek View Post
              I don't think anyone has suggested using a try block with no exception (until you arrived).
              You said
              Originally posted by suityou01 View Post
              Post 44, paragraph 1, sentence 2, clause 1.

              HTH BIDI
              Looking at Post 44, paragraph 1, sentence 2, clause 1, it says
              Originally posted by doodab View Post
              Testing for a null result is more expensive than a try block if no exception is raised
              That isn't having an exception without a try block, it's talking about not including a try block, but having to test afterwards whether the result is null or not.

              Until you posted in the thread, no-one suggested having a try block without an exception. Maybe you should stick to Oracle?
              Last edited by TheFaQQer; 13 February 2012, 14:41.
              Best Forum Advisor 2014
              Work in the public sector? You can read my FAQ here
              Click here to get 15% off your first year's IPSE membership

              Comment


                #67
                Originally posted by Sysman View Post
                That reminds me. Why do so many C/C++ programmers never bother checking error returns?
                Because the're bad coders and they write buggy, flaky software?

                With discipline and using tools like valgrind you can write robust C code that runs for years.

                Comment


                  #68
                  Originally posted by d000hg View Post
                  I can't remember the last time any of my apps crashed and took down the system... my C++ apps crash just the same way as my Java apps crash Don't MacOSX, Linux and modern versions of Windows protect against this?
                  Not so sure about that. In an early attempt to do something with Objective-C strings I created a memory leak in a tight processig loop. That brought the machine to its knees - the swapfile hit 3GB on a 640 MB system, and was growing

                  A reboot was the only way out.
                  Behold the warranty -- the bold print giveth and the fine print taketh away.

                  Comment


                    #69
                    Originally posted by TheFaQQer View Post
                    Well, eek said


                    You said


                    Looking at Post 44, paragraph 1, sentence 2, clause 1, it says

                    That isn't having an exception without a try block, it's talking about not including a try block, but having to test afterwards whether the result is null or not.

                    Until you posted in the thread, no-one suggested having a try block without an exception. Maybe you should stick to Oracle?
                    Absolutely. The original statement was about having a try block without raising an exception.

                    Knock first as I might be balancing my chakras.

                    Comment


                      #70
                      Originally posted by administrator View Post
                      Was reviewing some code the other day with the main developer for the site in question. In a comment written a couple of years ago:

                      /* Here be dragons, proceed with caution */

                      No clue as to exactly why the dragons existed there or what we should be cautious about
                      I've often wondered about that one myself. Apparently to do with ancient maps:

                      origin of phrase: Here be dragons; or Here there be dragons
                      Behold the warranty -- the bold print giveth and the fine print taketh away.

                      Comment

                      Working...
                      X