编码惯例 [英] Coding convention

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

问题描述

考虑以下代码(包含在类方法中):


开关($ sectionType)

{

case ''layout'':

返回$ this-> getLayoutSection($ sectionName);

break;

case''content'' :

返回$ this-> getContentSection($ sectionName);

休息;

}


显然这两种方法都不会被执行,因为这种方法会在它到达之前返回



我养成了放置的习惯在

开关的每个案例结束时中断,即使没有必要(如上所述)。我把它放在

的某个地方我的脑海里,这是适当的。做事的方式。但是现在我想起来了,我不得不问,这是真的吗?它是否考虑好

练习总是结束案例陈述,即使没有必要的时候也要结束?


我''我想听听别人对此的看法。谢谢!


此致,

-Josh

解决方案

sectionType)

{

case''layout'':

return


this-> getLayoutSection(


sectionName);

break;

case''content'':

return

Consider the following code (contained in a class method):

switch($sectionType)
{
case ''layout'':
return $this->getLayoutSection($sectionName);
break;
case ''content'':
return $this->getContentSection($sectionName);
break;
}

Obviously neither break is going to get execute, because the method will
return before it gets to them.

I have gotten into the habit of putting breaks at the end of every case in a
switch, even if it is not necessary (as the above). I have it somewhere in
the back of my head that this is the "proper" way to do things. But now
that I think about it, I have to ask, is this true? Is it consider good
practice to always end case statements with a break, even when not
necessary?

I''d like to hear others'' thoughts on this. Thanks!

Sincerely,
-Josh

解决方案

sectionType)
{
case ''layout'':
return


this->getLayoutSection(


sectionName);
break;
case ''content'':
return


这篇关于编码惯例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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