本文介绍了有条件的样式:如果(0 == resultIndex)VS如果(resultIndex == 0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们大多数人这样写条件语句:

Most of us write conditionals like:

if (resultIndex == 0)

...但我occaisionally碰到有人写他们这样的:

...but occaisionally I come across someone writing them like:

if (0 == resultIndex)

...和有趣的人已经作者和看似非常热打码机。

...and interestingly those people have been authors and seemingly pretty hot coders.

那么,为什么有些人选择'倒退'的风格?有一些背后的历史? ?Readabililty

So why do some people choose the 'backwards' style? Is there some history behind it? Readabililty?

重复:的

推荐答案

这已经被问过无数次,虽然我似乎无法找到的DUP。

This has been asked numerous times before though I can't seem to find the Dup.

从本质上讲,这种风格是从C宿醉凡

Essentially, this style is a hangover from C where a common mistake for

if (c == 5) //Comparison

if (c = 5) //Assignment

在在后一种情况下,编译rwould不会抱怨这样的人写的,像这样来减少这种情况的发生。

In the latter case, the compile rwould not complain so people wrote it like so to reduce the likelyhood of this happening

if (5 == c)

这篇关于有条件的样式:如果(0 == resultIndex)VS如果(resultIndex == 0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 02:44