如何寫代碼,才能越寫越輕鬆?

        畢業後一直在如今這家小公司,從什麼都不懂,到如今能夠單獨作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不是一個頗有自信的人,別人給定一個標準,而且按照這個標準去作,會以爲壓力很小,但若是本身給本身定標準,就會常常懷疑這個標準是否被別人接受(典型的受虐傾向)。就像上邊這段代碼,本身寫的,但總存在一種懷疑態度,並且是那種沒有一點根據,或者道聽途說的懷疑。 javascript

        還有像下邊這段爛到家的代碼,寫起來很舒服,但再來看,就懷疑這段代碼是本身寫的麼, php

$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;

        我糾結於不知如何去寫代碼,要實現的功能,這段代碼已經實現了,若是從用戶的角度來講,他不會看我寫的源代碼,但總以爲這樣的代碼會讓本身愈來愈累,沒有一點進步,僅僅是寫代碼。以爲這樣給本身形成的後果是寫代碼越寫越累。 java

        而想向各位請教的是: mysql

        一、如何可以寫出安全,效率,複用性高,能讓本身越寫越輕鬆、越寫越開心的代碼。 web

        二、如何在用戶或者設計人員在變動需求、UI的過程當中,可以提早規劃,最大程度的減小廢棄代碼的編寫。
sql

        三、對於愈來愈多的新技術,應該以一種什麼樣的心態去學習。 數據庫

相關文章
相關標籤/搜索