網站程式設計師如何應對web標準(1)

本文討論的是在web標準普及的形勢下,網站程式設計師的定位以及如何與設計師配合開發符合web標準的網站項目。

本文適合的讀者是傳統table布局下分工不是非常明晰的程式設計師。

1:學習web標準,讓你的工作變得更加簡單。

web標準是大勢所趨,所以作為網站程式設計師。你必須洗腦,必須去學習web標準。去重新認識html標籤,去了解如何讓程式輸出頁面需要的代碼。

比如:

 

 

上邊是美工出來的效果圖,下邊是符合標準的程式代碼:

dim ohtml

set rs=server.createobject("adodb.recordset")

sql = "select top 10 id,title from tbl_news order by id desc"

rs.open sql,conn,1,1

ohtml="<ul>"

do while not rs.eof

ohtml=ohtml & "<li><a href=""shownews.asp?id=" & rs("id") & """ title=""" & rs("title") & """>" & rs("title") & "</a></li>"

rs.movenext

loop

ohtml=ohtml & "</ul>"

rs.close

set rs=nothing

response.write (ohtml)

而如果是傳統的table布局下,程式設計師要寫的html代碼就會多很多,要寫出table、要判斷什麼時候輸出tr來換行、要在每條新聞的前邊加個一個img來輸出小圖示、要用程式去控制輸出的標題長度。所有的工作都需要先出頁面代碼,程式設計師才能去寫出這段程式。

對於程式設計師而言,你應該把web標準當成是一種福音,你應該把它當聖經一樣去讀,去了解頁面代碼到底需要什麼,明白之後你就會發現。你比以前要輕鬆多了。由於web標準注重的是表現與內容相脫離,而程式只負責內容數據。從此你就不再需要考慮用程式代碼如何控制隔行換色、一行分幾列輸出等等。你需要去做的,就是向頁面輸出最直接的內容,沒有任何裝飾的內容。

當然如果你是用.net開發的話,你就可以更徹底一點了。你可以完全將工作重點放在建立對象、類庫、數據訪問等,向表現層提供方法即可。下邊的例子是我以前做項目的,應該有點參考價值。

2:網站程式設計師,別讓html標籤阻擋了你的視線。

如果你覺得你真的非常討厭繁瑣的html標籤,而且自己的學習方向也不在網站的表現層,那你就和html標籤徹底地說再見吧。

我曾經在傳統桌面軟體開發的公司工作,程式設計師都不會html,網站項目緊的時候又不得不讓他們來幫忙。我們就拿著visual studio .net 2003自帶的幾個例子仔細分析,按照面向對象的結構化分層開發模式,也能非常好的進行配合。以新聞模組的開發為例:

第一步:網站程式設計師可以按需求分析進行資料庫設計,你可以負責建表、編寫存儲過程。這類的事情程式設計師都非常的熟悉。

第二步:定義對象。將網站的信息對象化,比如:

public class news

protected _id as integer

protected _typeid as integer

protected _title as string

protected _author as string

protected _original as string

protected _updatetime as datetime

protected _content as string

protected _clickcount as integer

public property id() as integer

get

return _id

end get

set(byval value as integer)

_id = value

end set

end property

public property typeid() as integer

get

return _typeid

end get

set(byval value as integer)

_typeid = value

end set

end property

public property title() as string

end property

public property author() as string

end property

public property original() as string

end property

public property updatetime() as datetime

end property

public property content() as string

end property

public property clickcount() as integer

end property

end class

就像這樣,把網站裡所有的表都試著對象化。然後再定義對象相關的記錄集,上邊定義的是單個的新聞對象,再定義一個新聞的記錄集。

public class newss

......

end class