• 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

Spacecadet

Double Godlike!
Joined
Mar 22, 2006
Messages
12,451
Likes received
53
Thanks received
16
Location
Jupiter
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 ******* SAME!

What a lot of programmers seem to need is a decent grounding in boolean algebra!
 
Be fair - you'll get he right result most of the time :rolleyes:
 
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 ******* 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..
 
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..

:yay:
 
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.
 
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
 
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: 09:29
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.
 
.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: 10:22

Advertisers

Back
Top