views:

248

answers:

6

In the database you have a table with a bit field, let call that field Active

In the application you have a variable boolean, let call it NotActive

Everytime you get the field from the table, in the application you have switch the meaning of the variable.

NotActive = !mytable.active;

Another example would be a bit field in the database named Enable__yes__no and in the code you do

control.enabled = !mytable.Enable_yes_no

best practice would be to keep the same name and the same meaning, but the pattern above, how to you call that?

+6  A: 

Obfuscation by design?

Developer Art
Non-desobfucation by sorta-design also known as NDeso_DesgnPoo
mjv
+3  A: 

Backward compatibility with existing databases?

Alex Reitbort
Sorry Alex but are you being serious here?
Lazarus
A: 

I think the problem here is in the architecture, not in the specific naming of the data. For instance, if you used an entity framework, then your entity for this table could declare a property called InActive, and it could use the Active column as the datastore. As far as the outside world is concerned, the translation back and forth is transparent.

Scott Whitlock
+12  A: 

I wouldn't name boolean variables with a negative prefix.

Name the variable IsActive or Active, naming it NotActive is double negation.

Edit/Clarification:

If you need to check if the thing is active, you need a double negation:

If (!NotActive) { DoSomething() }

Positive boolean Variable names are much easier to understand:

If (isActive) { DoSomething() }
danimajo
Double Negotiation? Do you mean Double Negation?
George Stocker
+1: I was also going to say this. Calling a variable NotXXX is the bad pattern. Good point. A better name would be Disabled.
Scott Whitlock
Just rename the variable IsNotNotActive. Now the logic is positive again.
Ryan Michela
NotActive is not a double negation, it's a single negation. NotInactive would be closer to a double negation.
Frerich Raabe
"not...negation"... ;)
Lazarus
A: 

I would call it ugly...

Maximilian Mayerl
+1  A: 

It's widely known as the "not-not-negative spaghetti confusion pattern" and was first mentioned 1972. ;-) SCNR

arno