• 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

    #31
    using Java and .NET where the runtime holds your hand and makes it easier for mediocre programmers to survive. If they had to code in C/C++
    .NET yes but Java? Incomprehensible. Even MFC was easier. If Fidel Castro has written a programming language it would have been Java.
    bloggoth

    If everything isn't black and white, I say, 'Why the hell not?'
    John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

    Comment


      #32
      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.
      But that wasn't what you were originally complaining about. If its null when you are trying to create an object that's should be an error, if its null when retrieving an object that's plausible.

      You are however forgetting that people don't like raising errors as that means you have to do proper error trapping and handling which requires thinking and that will never occur.
      merely at clientco for the entertainment

      Comment


        #33
        Originally posted by xoggoth View Post
        .NET yes but Java? Incomprehensible. Even MFC was easier. If Fidel Castro has written a programming language it would have been Java.
        Java and C# have virtually the same syntax, which is largely the result of Microsoft copying Java.

        Comment


          #34
          Originally posted by eek View Post
          But that wasn't what you were originally complaining about. If its null when you are trying to create an object that's should be an error, if its null when retrieving an object that's plausible.
          I was complaining about people writing java like it's C, i.e. returning null to indicate an error condition rather than raising an exception. One could see from reading the code it was written in a particular idiomatic C style. The only thing missing was an attempt at a static global Errno class.

          In this case the only reason the results would be null was because the object had not been initialized properly at create time because one of the 20 or so mostly unnecessary parameters to the constructor was null. This should result in an exception from the constructor, not a null pointer exception from somewhere inside the offending class 3 minutes later.

          This particular guy, not knowing about 'throw', was returning a ****ed up object, calling a method called isValid() (that was broken too) to see if the constructor had worked, and then proceeded to invoke methods on the class that would either result in a null pointer exception or a null result which may or may not get checked

          The 20 or so constructor parameters were being passed down a chain of constructors calling constructors 4 or 5 deep, with the various objects holding references to their parent to access certain fields.

          The worst one I have seen was an attempt at recreating function-per-file modularity where each class had a single static method in it.

          Another sign of a C programmer who is converting to java is returning an int status code from a method to indicate an error so that every method call has to be followed by an if (result != 0) spaghetti monster rather than using a try-catch block. Which you need anyway to catch the null pointer exceptions
          Last edited by doodab; 13 February 2012, 13:07.
          While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'

          Comment


            #35
            Originally posted by eek View Post
            But that wasn't what you were originally complaining about. If its null when you are trying to create an object that's should be an error, if its null when retrieving an object that's plausible.

            You are however forgetting that people don't like raising errors as that means you have to do proper error trapping and handling which requires thinking and that will never occur.
            I agree returning null from a method where you are querying for a specific object , if its not found then it should return null, not throw an exception as they are expensive, this though leads to lots of if (obj == null) all over the shop.

            Comment


              #36
              Originally posted by russell View Post
              Yeah but a bad C/C++ program can do much more damage than a managed program. Can take down the whole system if you can't properly manage memory or work with pointers etc.
              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?
              Originally posted by MaryPoppins
              I'd still not breastfeed a nazi
              Originally posted by vetran
              Urine is quite nourishing

              Comment


                #37
                Originally posted by Spacecadet View Post
                Sounds like a bad programmer rather than a problem of moving from C/C++ to Java
                It's fair to say the guy in question wasn't a very good C programmer either.
                While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'

                Comment


                  #38
                  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

                  Comment


                    #39
                    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?
                    Java and C# don't run directly on the metal, they are managed by a runtime. Granted you don't see Linux kernel crashing much, but you must remember BSOD, no doubt caused by unmanaged code.

                    Comment


                      #40
                      Was having a discussion on here some time ago with a .Net "guru". It turns out he wanted to use data binding to populate a control where was iterating through a dataset to build a simple array and then iterate through this array to populate the control was all that was needed.
                      Knock first as I might be balancing my chakras.

                      Comment

                      Working...
                      X