Jul
05
2007
2

“PHP Eats Rails for Breakfast” ?

Ruby on Rails 的出現,令 Ruby 近年崛起得極快。因此很多都說 Ruby 將會成為 “PHP-killer”。

但這篇統計文章卻完全否決了有關言論:

http://www.ohloh.net/wiki/articles/php_eats_rails

Ohloh 是一個 Open Source Directory, 數據方面相當客觀及覆蓋廣泛的。

Written by Chris Lam in: 程式編寫 |
Feb
24
2007
0

首個 100% CSS+XHTML+Tableless 網頁

原本 daplugin.com 是在傳統 Table 排版以及大量陋習下做出來的,但始終覺得要給全世界那麼多國家的人看實在太丟人了,於是決心把網站從新寫過。

起初改用 CSS 排版很不習慣,經常弄至 DIV 左疊右疊 =3=

幸好只是習慣的問題,陋習及 XHTML 的 Tag 改變方面則有 Rapid PHP Editor 幫忙,所以很快就適應過來。

難得踏出一步,昨晚趁爹娘上了祈福就叫了個大芝心夏威夷獎勵自己 A_A

Written by Chris Lam in: 程式編寫, 網絡資源 |
Jan
19
2007
0

在 Tomcat 下運行 JSP + MySQL / PostgreSQL

要在 Tomcat 下使用 MySQL 及 PostgreSQL, 首先要下載 JDBC Driver.

MySQL Connector: http://dev.mysql.com/downloads/connector/j/5.0.html

PostgreSQL Driver: http://jdbc.postgresql.org/download.html#jars

下載後把兩個 jar 檔案放在 /usr/local/tomcat/common/lib (或其他已設置好的 Classpath)

然後 JSP 檔案中要 import java.sql 中的 API classes:

  1. <%@ page import="java.sql.*"%>

JSP + MySQL:

  1. <%@ page contentType="text/html;charset=big5"%>
  2. <%@ page import="java.sql.*"%>
  3.  
  4. <%
  5.  
  6. Class.forName("com.mysql.jdbc.Driver").newInstance();
  7. String db_url ="jdbc:mysql://localhost/db_name";
  8. String db_user="db_user";
  9. String db_pw="db_pwd";
  10. Connection conn=DriverManager.getConnection(db_url, db_user, db_pw);
  11. Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  12. String sql="SELECT id, name FROM table1";
  13. ResultSet rs=stmt.executeQuery(sql);
  14.  
  15. while(rs.next())
  16. {
  17. %>
  18. <%=rs.getString(1)%> <%=rs.getString(2)%>
  19.  
  20. <%
  21. }
  22.  
  23. rs.close();
  24. stmt.close();
  25. conn.close();
  26. %>

JSP + PostgreSQL:

  1. <%@ page contentType="text/html;charset=big5"%>
  2. <%@ page import="java.sql.*"%>
  3. <html>
  4. <body>
  5. <%
  6. //Class.forName("org.gjt.mm.mysql.Driver").newInstance();
  7. Class.forName("org.postgresql.Driver").newInstance();
  8. String db_url ="jdbc:postgresql://localhost/admin_test1";
  9. String db_user="da_admin";
  10. String db_pw="g639604";
  11. Connection conn= DriverManager.getConnection(db_url, db_user, db_pw);
  12. Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  13. String sql="SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'";
  14. ResultSet rs=stmt.executeQuery(sql);%>
  15. <%while(rs.next()) {%>
  16. <%=rs.getString(1)%>
  17.  
  18.  
  19. <%}%>
  20. <%rs.close();
  21. stmt.close();
  22. conn.close();
  23. %>
  24. </body>
  25. </html>
Written by Chris Lam in: 程式編寫 |
Jan
06
2007
0

錯誤的 oo 概念

昨天看了很多同學的 java 功課…發覺大家根本不知道何謂 oo

無他,因為老師都是這樣灌輸錯誤的訊息給我們。

好不容易才找回這兩篇文章:

http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html

http://www.javaworld.com/javaworld/jw-01-2004/jw-0102-toolbox.html

該文章解釋了 getter/setter methods 不應該出現在 oo 中,因為 oo 的真義是要實行 implementation hiding.

小弟認為文中最精警的一句:

Don’t ask for the information you need to do the work; ask the object that has the information to do the work for you.

但學校的 notes, lab, 某些同學所做的功課,偏偏要為每個 attribute 寫 getter 及 setter, 簡直多此一舉。

加長程式長度之餘,又使程式更難維護 (因做不到 implementation hiding),這些都不是 oo 的原意。明明百多行便可完成,偏偏要寫數百行,何必呢?

Written by Chris Lam in: 程式編寫 |
Nov
17
2006
0

? VS ?

最近在 WHT 論壇掀起了不少語言之間的比較爭論,而這個帖更有會員以實例來比較 PHP, Python 及 Ruby 等:

http://webhostingtalk.com/showthread.php?t=562380

值得一看。

Written by Chris Lam in: 程式編寫 |

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes