新公司一外包项目的代码,我要吐了,我想发飙

麦地兜兜 发布于 2011/07/03 00:14
阅读 1K+
收藏 0

招人实在困了,前期公司为了进度,把项目外包给别人了.我们公司的项目是一个iPhone活动社交项目,我负责维护服务端代码

下面是这个恶心的代码

if($this->sort == 0){
			$sql = sprintf(
				"SELECT
					act.`activity_date`,
					act.`id`,
					act.`activity_in_count`,
					act.`activity_join_count`,
					act.`activity_follow_count`,
					act.`activity_name`,
					act.`activity_status`,
					act.`activity_start`,
					act.`activity_end`,
					act.`activity_location`,
					act.`activity_lat`,
					act.`activity_lng`,
					act.`activity_image`
				FROM %s as uact INNER JOIN %s as act
				WHERE uact.`activity_id` = act.id  and act.activity_status!=1
					and uact.`user_activity_type` = %s
					and `user_id` = %s and act.`activity_start` >= \"%s\"
				ORDER BY activity_start ASC LIMIT 0, %s",
				T_USER_ACTIVITY,
				T_ACTIVITY,
				ACTIVITY_TYPE_JOIN,
				$this->current_uid,
				$this->time,
				$this->count
			);
		}else{
			$sql = sprintf(
				"SELECT
					act.`activity_date`,
					act.`id`,
					act.`activity_in_count`,
					act.`activity_join_count`,
					act.`activity_follow_count`,
					act.`activity_name`,
					act.`activity_status`,
					act.`activity_start`,
					act.`activity_end`,
					act.`activity_location`,
					act.`activity_lat`,
					act.`activity_lng`,
					act.`activity_image`
				FROM %s as uact INNER JOIN %s as act
				WHERE uact.`activity_id` = act.id  and act.activity_status!=1
					and uact.`user_activity_type` = %s
					and `user_id` = %s and act.`activity_start` <= \"%s\"
				ORDER BY activity_start ASC LIMIT 0, %s",
				T_USER_ACTIVITY,
				T_ACTIVITY,
				ACTIVITY_TYPE_JOIN,
				$this->current_uid,
				$this->time,
				$this->count
			);
		}

 

你们看出有什么不同了么? 唯一的不同就是 WHERE字句后面的 act.`activity_start` 字段后面的 >= 操作符.

这样的语句在iPhone对PHP的调用接口中有32个之多,这还不算,api调用而且还全部是用的if else 之类的玩意儿,我要发飙了.

我决定了,我要提出验收不通过,卡他们的尾款,气死我了.

加载中
0
麦地兜兜
麦地兜兜

不考虑SQL注入的问题了,先重构再说.我草泥马哟.整死个人.TMD太缺德了.下面是原始的代码

	if($sort == 0){
		$sql = "SELECT act.`activity_date`,act.`id` , act.`activity_in_count`, act.`activity_join_count`, act.`activity_follow_count`, act.`activity_name`, act.`activity_status`, act.`activity_start`, act.`activity_end`, act.`activity_location`, act.`activity_lat`, act.`activity_lng`, act.`activity_image`, act.`activity_price` FROM $g_db_user_activity_table as uact INNER JOIN $g_db_activity_table as act WHERE uact.`activity_id` = act.id  and act.activity_status!=1 and uact.`user_activity_type` = $user_activity_type_in and `user_id` = $target_uid and act.`activity_start` >= \"$time\" ORDER BY activity_start ASC LIMIT 0, $count";
	}else{
		$sql = "SELECT act.`activity_date`,act.`id`, act.`activity_in_count`, act.`activity_join_count`, act.`activity_follow_count`, act.`activity_name`, act.`activity_status`, act.`activity_start`, act.`activity_end`, act.`activity_location`, act.`activity_lat`, act.`activity_lng`, act.`activity_image`, act.`activity_price` FROM $g_db_user_activity_table as uact INNER JOIN $g_db_activity_table as act WHERE uact.`activity_id` = act.id  and act.activity_status!=1 and uact.`user_activity_type` = $user_activity_type_in and `user_id` = $target_uid and act.`activity_start` <= \"$time\" ORDER BY activity_start ASC LIMIT 0, $count";
	}
jinceon
jinceon
下面是原始的代码..你重构的代码?
0
麦地兜兜
麦地兜兜
还有iPhone客户端的代码也是如此.
0
p
pjiaxu.com
我了个去,PHP就这些让他给毁了!
0
ValueError
ValueError
确实,值得一呕
0
ClownFish
ClownFish
晕!真没见过这么恶心的代码?跟凤姐有的一拼
0
TestXd
TestXd

引用来自“pjx”的答案

我了个去,PHP就这些让他给毁了!

为啥要用sprintf ,直接双引号就行了啊。

0
智勇
智勇
哈哈我现在就在一个外包公司,看着别人的代码时和你深有同感
0
火眼金睛容嬷嬷
火眼金睛容嬷嬷
有些公司是号称不收尾款的,呵呵
0
fmxzhou
fmxzhou
呵呵,小弟学习了!!!!
返回顶部
顶部