如何写代码,才能越写越轻松?

        毕业后一直在现在这家小公司,从什么都不懂,到现在可以单独做web项目,有了一些进步,但现在又遇到了新的问题,下边这段代码或许能够说明问题


<?php
	include_once("mysqlConnect.php");//连接数据库
	include_once("api_config.php");//配置
	session_start();
	if(isset($_POST["invitees"])){
		$invitees = $_POST["invitees"];
		$leaderId = $_SESSION["userInfo"]["uId"];
		$uTelephone = $_SESSION["userInfo"]["telephone"];
		if($uTelephone == $invitees){
			echo '(function(){alert("'.$config_6.'");document.getElementById("telephone").value="";document.getElementById("telephone").focus()})();';
			exit;
		}
		$isInvited = $n->getlist("select * from invite where leaderId = {$leaderId} and memberPhone = '{$invitees}' and state = 0");
		if(!count($isInvited)){
			if(!$db->query("insert into invite (leaderId,memberPhone) values ($leaderId,'{$invitees}')")){echo '(function(){alert("error")})()';}
			echo '(function(){rexseeSMSSender.send("sendSms","'.$invitees.'","'.$config_4.'");})()';
		}else{
			echo '(function(){alert("'.$config_5.'");window.location.href = "user.php";})();';
		}
		
	}
?>

        总觉得这样的代码存在问题,安全性,效率性,维护性好像都能被吐槽。LZ不是一个很有自信的人,别人给定一个标准,并且按照这个标准去做,会觉得压力很小,但如果自己给自己定标准,就会经常怀疑这个标准是否被别人接受(典型的受虐倾向)。就像上边这段代码,自己写的,但总存在一种怀疑态度,而且是那种没有一点根据,或者道听途说的怀疑。

        还有像下边这段烂到家的代码,写起来很舒服,但再来看,就怀疑这段代码是自己写的么,

$bangdan =<<<End
	<div class="second" id="frozen" style="display:none">
		<div class="cont" style="padding:0px;">
			<div style="border-bottom:1px solid #e2e2e2; padding:0.7em 0.5em 0.2em 0.5em;">
				<span style="font-size:1em;color:#2d9fc9">昨日投注榜单</span><span style="font-size:0.8em;color:#999">(统计于{$thisOrderTime})</span>
			</div>
			<div style="padding:0px;">
				<div class="chart">
End;
	$totalAssRank = $n->getlist("select * from fb_user where lastFrozen > 0 order by lastFrozen desc,user_id limit 20");
	foreach($totalAssRank as $k=>$v){
		t_checkCapital($v["user_id"],$v["receipt_earnings"],$v["esn"],$v["unreceipt_earnings"],$v["earnings_time"]);
		$userId =$v["user_id"];
		$userName = $v["user_name"];
		$usercapital = $v["lastFrozen"];
		$head = getUpPhoto($v["up_id"]);#头像
		$newCapitalInfo = "<img src='img/more-dark.png' alt='' style='width:24px;height:24px;border:0px;'/>";#新资金是否到账
		t_checkCapital($v["user_id"],$v["receipt_earnings"],$v["esn"],$v["unreceipt_earnings"],$v["earnings_time"]);
		$isNewPriInfo = $v["receipt_earnings"];
		if($isNewPriInfo){$newCapitalInfo = "<span>奖金到账</span>";}
		$bangdan.=<<<End
		<div onclick="javascript:rexseeBrowser.go('p_user.php?stealer={$userId}')" style="padding:0.5em 0.5em 0.3em 0.5em;" name="newCapitalInfo">
				<table width="100%">
					<tr>
						<td><img src="{$head}" alt="" style="height:32px;width:32px;" onerror="javascript:this.src='img/head.png'"/></td>
						<td style="width:6.5em"><div style="width:5em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" >{$userName}</div></td>
						<td style="font-size:0.8em;width:5em;">{$usercapital}</td>
						<td style="font-size:0.8em; color:#2d9fc9;padding-right:0.5em;" align="right" name="stealer{$userId}"><img src='img/more-dark.png' alt='' style='width:24px;height:24px;border:0px;'/></td>
					</tr>
				</table>
		</div>
End;
	}
		$bangdan.=<<<End
				</div>
			</div>
		</div>
	</div>
End;

        我纠结于不知如何去写代码,要实现的功能,这段代码已经实现了,如果从用户的角度来说,他不会看我写的源代码,但总觉得这样的代码会让自己越来越累,没有一点进步,仅仅是写代码。觉得这样给自己造成的后果是写代码越写越累。

        而想向各位请教的是:

        1、如何能够写出安全,效率,复用性高,能让自己越写越轻松、越写越开心的代码。

        2、如何在用户或者设计人员在变更需求、UI的过程中,能够提前规划,最大程度的减少废弃代码的编写。

        3、对于越来越多的新技术,应该以一种什么样的心态去学习。


转载于:https://my.oschina.net/u/273372/blog/115625

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值