Alex Rivera | Logout

Not keyword vs = False when checking for false boolean condition

Asked 2008-10-29T03:08:21.783
12

When I'm using an If statement and I want to check if a boolean is false should I use the "Not" keyword or just = false, like so

If (Not myboolean) then 

vs

If (myboolean = False) then

Which is better practice and more readable?

Edit
Report

1 Answer

1

Definitely use "Not", consider reading it aloud.

If you read aloud:

If X is false Then Do Y Do Y

Versus

If Not X Then Do Y

I think you'll find the "Not" route is more natural. Especially if you pick good variable names or functions.

Code Complete has some good rules on variable names. http://cc2e.com/Page.aspx?hid=225 (login is probably required)

answered 2008-10-29T04:36:26.473

Your Answer