开发者

Difference between these two things?

When people use if statements on booleans, they either do this

if booleanStatement = true then
if booleanStatement then

I know that they both accomplish the same thing, but is one better tha开发者_如何学Pythonn the other? Outside of 'good programming etiquette'


In terms of logic of your code, the difference is nil. However, at the risk of starting a war amongst myself and future answer posters, I would say that comes down to naming conventions and code readability.

For example, I would not say that booleanStatement is a very descriptive name. If you had something lie this:

If result.IsAboveAverage() Then DoSomething()

where the IsAboveAverage() method of result returns a Boolean is very readable, and therefore definitely does not need = true.

For most people who come from C/C++ writing something in the form booleanExpression == true is equivalent to crime against humanity. In .NET, however, some of these strict conventions seem to have been relaxed in terms of correct style, because its constituent programming languages were designed for great readability and therefore such things can be allowed for the same reason.

It is really up to you. As long as you pick one way and stick with it, you should not worry about it.


Use if booleanStatement then or if Not booleanStatement then. Why would you wanna write if true = true then or if true = false then?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜