• 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!

Boolean Algebra

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

    Boolean Algebra

    Someone recently posted a link to a blog which demonstrated using venn diagrams how table joins work in an RDBMS SQL system.

    We need something similar for "logic". I've lost count of how many times I've come across this sort of error:

    Business logic rules:
    Code:
    if statement1 
       or statement2
       or statement3
       or statement4 then result1
    else result2
    Crap programmer translates it to:
    Code:
    if not statement1 
       or not statement2
       or not statement3
       or not statement4 then result2
    else result1
    THEY'RE NOT THE F***ING SAME!

    What a lot of programmers seem to need is a decent grounding in boolean algebra!
    Coffee's for closers

    #2
    Be fair - you'll get he right result most of the time
    +50 Xeno Geek Points
    Come back Toolpusher, scotspine, Voodooflux. Pogle
    As for the rest of you - DILLIGAF

    Purveyor of fine quality smut since 2005

    CUK Olympic University Challenge Champions 2010/2012

    Comment


      #3
      Originally posted by Zippy View Post
      Be fair - you'll get he right result most of the time
      only if you're very lucky!
      Coffee's for closers

      Comment


        #4
        Originally posted by Spacecadet View Post
        Someone recently posted a link to a blog which demonstrated using venn diagrams how table joins work in an RDBMS SQL system.

        We need something similar for "logic". I've lost count of how many times I've come across this sort of error:

        Business logic rules:
        Code:
        if statement1 
           or statement2
           or statement3
           or statement4 then result1
        else result2
        Crap programmer translates it to:
        Code:
        if not statement1 
           or not statement2
           or not statement3
           or not statement4 then result2
        else result1
        THEY'RE NOT THE F***ING SAME!

        What a lot of programmers seem to need is a decent grounding in boolean algebra!
        But would you be complaining if crap programmer had done:-

        Code:
        if not statement1 
           and not statement2
           and not statement3
           and not statement4 then result2
        else result1
        or

        Code:
        if not (statement1 
           or statement2
           or statement3
           or statement4) then result2
        else result1
        Just interested like..

        Comment


          #5
          Originally posted by ASB View Post
          But would you be complaining if crap programmer had done:-

          Code:
          if not statement1 
             and not statement2
             and not statement3
             and not statement4 then result2
          else result1
          or

          Code:
          if not (statement1 
             or statement2
             or statement3
             or statement4) then result2
          else result1
          Just interested like..
          Coffee's for closers

          Comment


            #6
            Clearly that's a mistake but it should be pretty obvious when (if) they come to test it.

            What I can't stand seeing is lots of nested if statements when a single one could be used (eg if(object != null) { if (object.Item == "Test"); }). I've seen that kind of thing so many times from supposedly degree educated developers, pure lazyness.

            Comment


              #7
              Originally posted by Jaws View Post
              Clearly that's a mistake but it should be pretty obvious when (if) they come to test it.

              What I can't stand seeing is lots of nested if statements when a single one could be used (eg if(object != null) { if (object.Item == "Test"); }). I've seen that kind of thing so many times from supposedly degree educated developers, pure lazyness.
              I see a lot of nested case statements which have been hacked together over a period of time. Much like you describe there.
              Occasionally, I've found bits of case statements which would never be used, they just sit there untouched by logic like some sort of useless appendix.

              and then the surplus brackets in SQL

              and ((sales.customer_id) = (customers.customer_id))

              You start to question if they're writing the stuff themselves or getting access to do it for them, lazy idiots
              Coffee's for closers

              Comment


                #8
                The nested if statements of the form you describe are usually bug fixes.

                It starts with an incompetent permie writing

                Code:
                if (object.property == "xyz") 
                {...
                and then he (or an equally incompetent contractor bought in to fix the mess) has to fix all the null pointer exceptions so he wraps it in

                Code:
                if (object != null) 
                {...
                which may seem lazy, but you have to ask yourself, if you are asked to "take a look" at somebody else's code, which has 300 classes all of which should probably be named NullPointerExceptionFactory, what would you do?

                Of course, in an ideal world I would tell the numpty to wrap whatever API is returning null objects in a factory class that throws an exception, as personally I think that functions that require checking their return values for null have no place in a modern OO language.
                Last edited by doodab; 9 June 2010, 11:04.
                While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'

                Comment


                  #9
                  Originally posted by doodab View Post
                  The nested if statements of the form you describe are usually bug fixes.

                  It starts with an incompetent permie writing

                  Code:
                  if (object.property == "xyz") 
                  {...
                  and then he (or an equally incompetent contractor bought in to fix the mess) has to fix all the null pointer exceptions so he wraps it in

                  Code:
                  if (object != null) 
                  {...
                  which may seem lazy, but you have to ask yourself, if you are asked to "take a look" at somebody else's code, which has 300 classes all of which should probably be named NullPointerExceptionFactory, what would you do?

                  Of course, in an ideal world I would tell the numpty to wrap whatever API is returning null objects in a factory class that throws an exception, as personally I think that functions that require checking their return values for null have no place in a modern OO language such as Java or .Net.
                  .Net is NOT A PROGRAMMING LANGUAGE

                  Hth.

                  Comment


                    #10
                    Originally posted by Churchill View Post
                    .Net is NOT A PROGRAMMING LANGUAGE

                    Hth.
                    Of course, in it's entirety it's more than just a language, but then so is Java.

                    I think most people would, in this context, take Java to mean the Java language and .Net to mean the CIL and the higher level languages that target the framework. The high level languages aren't strictly part of .Net, as you so rightly pointed out, but many people treat .the term as a synonym for either C# or VB (but rarely both).

                    The CIL, which is both a language and part of .Net, is what I would call a modern OO langauge, i.e. it's object oriented, supports exceptions and doesn't require the developer to be responsible for memory management.
                    Last edited by doodab; 9 June 2010, 09:29.
                    While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'

                    Comment

                    Working...
                    X