编码风格的优化 [英] Optimization in coding style
问题描述
你好,
我想知道代码风格的优化是否有一点...我已经习惯在一些php周围加上括号关键字,但它们不需要
。
例如,我总是使用:
echo(" String .. 。");
但我可以使用
echo" String ..." ;;
同样的事情是返回:
返回($ tempHTML);
而不是
返回$ tempHTML;
还有一个点在字符串分隔符之间进行变换和''?
ie。如果我在一个字符串中没有任何变量,那么使用单引号而不是双引号会更好吗?例如:
''这是一个字符串......''
而不是
"这是一个字符串...... 。
需要双引号,当然在其他情况下:
坦率地说亲爱的,你的名字是$ {nameOfTheUser}!
我知道这听起来很愚蠢,甚至难以阅读,但你有什么看法?
- 渐渐潜伏 -
Hi there,
I was wondering is there a point in optimization in code style... I
have used to put parenthesis around some php keywords, but they are not
needed.
For example, I always use:
echo( "String..." );
but I could use
echo "String...";
the same thing is with return:
return( $tempHTML );
as opposed to
return $tempHTML;
Also is there a point to variate between string delimiters " and '' ?
ie. is it better to use single quotes instead of double quotes if I
don''t won''t any variable in a string? For example:
''This is a string...''
as opposed to
"This is a string...".
Double quotes are needed, of course in other cases:
"Frankly my dear, your name is ${nameOfTheUser}!"
I know it sounds stupid, even hard to read, but what are your opinions?
- Evanescent Lurker -
推荐答案
tempHTML);
而不是
return
tempHTML );
as opposed to
return
tempHTML;
还有一点要在字符串分隔符之间进行变换和''?
ie。如果我在一个字符串中没有任何变量,那么使用单引号而不是双引号会更好吗?例如:
''这是一个字符串......''
而不是
"这是一个字符串...... 。
需要双引号,当然在其他情况下:
坦率地说亲爱的,你的名字是
tempHTML;
Also is there a point to variate between string delimiters " and '' ?
ie. is it better to use single quotes instead of double quotes if I
don''t won''t any variable in a string? For example:
''This is a string...''
as opposed to
"This is a string...".
Double quotes are needed, of course in other cases:
"Frankly my dear, your name is
>
{nameOfTheUser}!"
我知道这听起来很愚蠢,甚至难以阅读,但您的意见是什么?
- 渐渐潜伏 -
{nameOfTheUser}!"
I know it sounds stupid, even hard to read, but what are your opinions?
- Evanescent Lurker -
这篇关于编码风格的优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!