What is the best style? '<>' or 'not =' / VBA

I got the impression that it’s always better to write:

If Not X = Y then

then

If X <> Y then

but I'm not sure where I did it. I get this idea :-).

Is there any better? Why do we have two ways to do the same thing?

Tks!

+4
source share
4 answers

Reading is the most important.

The second seems to me more natural. It seems wrong to use an equal sign and then add to it Not.

NotIMHO is best used with boolean functions such as IsNumeric(...)that lends itself to more natural reading of code, for example,

If Not IsNumeric(myNumberString) Then

Not to = False . , ...

If bFlag1 Then
If Not bFlag2 Then

... , ...

If bFlag1 = True Then ' <-- (This is totally redundant) = True
If bFlag2 = False Then
If a <> b = True Then ' <-- please don't ever do this
+7

. - , If (Not X) = Y Then.

? ... ? =, <> Not.

+2

:

Not , <> , , (. ).

, Not , , VBA.

+2

, If X <> Y Then... ( ). , , If Not X = Y Then... ( ), . , , ?...

, ; , Is (, Isn_t - ), If Not X Is Y Then...

+1

Source: https://habr.com/ru/post/1540775/


All Articles