if语句的写法之普通,文艺,2B青年写法

最近这段时间在处理一个项目迁移,结果有大量的时间在写迁移代码。

发现软件确实是门工艺,是需要有充足的时间和精力去做些一些重复的事情,这样才能有技能上的提高。

下面就用一个很普通常见的参数判断的例子来说明,很简单,但是在工作中也会经常遇到。

先看普通青年版本的写法

private boolean putongCheck(String paramter) {

		if (null == paramter || "".equals(paramter)) {
			return false ;
		}else {
			return true;
		}
	}

我想很多人在刚介入这个行业的时候会经常写类似的代码。

—————————————————————————

下面来看文艺青年是怎么写的。

private boolean wenyiCheck(String paramter) {

		return (null == paramter || "".equals(paramter))?false : true;
	}

这个版本稍微好了点,用了三目运算符号,简洁易懂。

—————————————————————————

最后看下2B青年是怎么写的吧。

private boolean twoBCheck(String paramter) {

		return !(null == paramter || "".equals(paramter));
	}

这个版本的代码就更少了,但是可读性性上就缺少了点。

上面只是按照条件判断举个例子,编码时可以扩展到很多地方。

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>