逻辑是否相异 [英] Logical if difference

查看:39
本文介绍了逻辑是否相异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我遇到了这样的代码:

Recently, I came across a code like this:

if (0 === $something) { }

上面的代码和以下代码之间是否有任何区别?

Is there any difference between the code above with:

if ($something === 0) { }

推荐答案

实际上,无论是性能方面还是功能方面都没有区别.我可以说这是个人选择的编码样式,通常称为 Yoda样式

Actually there is no difference in both performance wise or in functional perspective. I can say it's a personal choice of coding style often called that as Yoda Style

在编程术语中,Yoda条件(也称为Yoda表示法)是一种编程样式,其中表达式的两个部分在条件语句中被反转.

In programming jargon, Yoda conditions (also called Yoda notation) is a programming style where the two parts of an expression are reversed in a conditional statement.

我更喜欢后一种方法,因为第一种方法会破坏代码的可读性(至少对我来说是 )

I prefer the later way as the first way kills the readability of code (at least for me)

这篇关于逻辑是否相异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆