如果引用或轉貼,麻煩註明出處與本網誌連結,否則視為侵權。

2005年1月3日

Quickplace Placebot能做些什麼?

Fred Wang(Hsinchu-Taiwan) (http://fmwang.blogspot.com) 日期 : 2005/01/03

1. 記錄所有的文件 : 將所在的Room(placebot所在的Room)內所有的文件title寫在log內

2. Room Map : 在某一網頁內以樹狀方式或表格列出所在的Room內所有的文件連結

3. Site Map : 在某一網頁內以樹狀方式或表格列出網站(Place)內含Rooms and Subrooms內所有的Folders及文件連結 (註: Quickplace 3.0版以經有預設的功能)
  • 可以用圖示區分Home, Rooms, Folders and Documents
  • 顯示每個資料庫Home and Rooms的大小
  • 顯示每個文件的大小, 最近更改日期及作者等
  • 可選擇性排除或選入特定的Rooms, Folders and Documents, 例如: Index不顯示
  • 新增文件後會自動更新
4. 首頁顯示最新幾則News的標題連結, 或稱為公告欄 : News或Announcement(公告)在特定的Folder內維護, 透過placebot抓取最進n則的title and link顯示在首頁(welcome)內的PageBody. 也可以用Java Applets or MARQUEE tag做到動態的新聞或公告走馬燈功能, 不過我不建議採用動態的方式, 另外可增加 “More…” 的連結文字, 可連至News所在的Folder讓使用者可以看到過去的新聞或公告

5. 將傳入網站的信件分門別類存放 : 請見Redbooks “Customizing Quickplace” 7.5

6. 建立網站圖形化的統計圖 : 請見Redbooks “Customizing Quickplace” 7.6

7. 將Notes Database的資料同步複製(Mirror)到Quickplace中 : 請見Redbooks “Customizing Quickplace” 10.1

8. 文件格式轉換
  • 將Quickplace文件轉成Text file
  • 將Quickplace文件轉成eMail格式並傳送給特定人員
9. 資料的複製,備份及刪除
  • 複製整個Room
  • 複製某Folder
  • 過期資料備份及刪除
10. 權限控制及變更
  • 增加一個成員到不同的Rooms內
  • 透過特定Form的文件產生來建立新的成員
  • 增加編輯者權限到新產生的文件
  • 定時更新某Room或Folder的權限
11. 用 Placebot 讓某文件產生後直接redirect到特定網址或網頁

12. 用一個按鈕來執行 placebot

13. 資料擷取
  • 定期存取某Folder的資料彙整成表格顯示在另一個網頁
  •  定期存取特定Notes Database的某個View的資料彙整成表格顯示在另一個網頁
  •  

JSP and Struts開發經驗

JSP and Struts開發經驗
Fred Wang(http://fmwang.blogspot.com)
2005/01/03

JSP
JSP程式的錯誤難以測試
* JSP程式混合多種語法,包含HTML,JSP script,Java,Javascript, CSS
* 發生錯誤時執行期才會顯示出來
* 執行期產生的錯誤訊息顯示錯誤的程式行數並非JSP的程式行數,而是Web Server將JSP翻譯成Servlet後的程式行數,如果用Tomcat做Web Server還可以找到翻譯後的Servlet程式,但是其他Web Server可能就沒有了。

因應之道
* 盡量簡化JSP的程式碼,避免複雜的邏輯,盡量是單純的HTML
* 減少java scriptlet的使用
* 利用Tag library,如Struts tags, JSTL tags

Jakarta Struts
Struts Tag的使用要嚴格檢查
* HTML是給Web browser讀的,而這些browser由容錯機制,因此HTML寫錯或starting tag and closing tag不搭配時也不會造成無法執行的嚴重錯誤,但是Struts tags會經由web container及API解譯,如果有錯就會造成編譯的錯誤,而無法執行,因此這點是要特別注意的。

Struts Tag 並非標準
* 建議採用JSTL取代Struts相關的Logic, Bean等tag library,只保留struts html tag for Action Form bean的使用。

盡量使用ForwardAction以減少Java程式的數量
* 透過ForwarAction可以將許多存取對象(Domain object)相同的action集合到同一個class內處理。如此不但減少維護的程式量也可以撰寫helping method將共同的程式碼extract成共用的method。

使用Tiles , Template或Include提高JSP程式的可維護性
* 網頁往往有許多共同的部分如: Heading, Sidebar, Footer, Main Menu, Banner等區,這些區域可以透過Tiles , Template或Include等方式讓這些部分不會重複撰寫,提高JSP程式的可維護性。

如何寫出無法維護的程式 - 命名 1-5

原作 : How To Write Unmaintainable Code ©1997-2004 Canadian Mind Products
中譯 : Fred F.M. Wang 2005/1/3


命名Naming
©1997-2004 Canadian Mind Products

"When I use a word," Humpty Dumpty said, in a rather scornful tone, "it means just what I choose it to mean - neither more nor less."
Lewis Carroll -- Through the Looking Glass, Chapter 6

寫無法維護的程式許多的技巧是在變數與方法命名上,這些技巧並不會被編譯器視為錯誤,這讓你有大量的自由使用這些技巧把維護程式者搞得昏頭轉向。
Much of the skill in writing unmaintainable code is the art of naming variables and methods. They don't matter at all to the compiler. That gives you huge latitude to use them to befuddle the maintenance programmer.

1. New Uses For Names For Baby 用嬰兒命名的方式命名
買本嬰兒命名書,那麼你就不缺變數名稱。例如一些容易輸入的字如Fred。其他像鍵盤上鄰近的字如adsf等。
Buy a copy of a baby naming book and you'll never be at a loss for variable names. Fred is a wonderful name, and easy to type. If you're looking for easy-to-type variable names, try adsf or aoeu if you type with a DSK keyboard.

2. Single Letter Variable Names用單一字母的變數名稱
如果用a, b, c 這類的字就無法用簡單的文字編輯器找到使用它的地方。而且沒有人可以猜的出來這變數是幹麼用的。
: If you call your variables a, b, c, then it will be impossible to search for instances of them using a simple text editor. Further, nobody will be able to guess what they are for. If anyone even hints at breaking the tradition honoured since FØRTRAN of using i, j, and k for indexing variables, namely replacing them with ii, jj and kk, warn them about what the Spanish Inquisition did to heretics.

3. Creative Miss-spelling使用有創意的錯別字
如果你要用描述性的變數及功能名稱,就用拼錯的字,或有些對有些錯的組合如SetPintleOpening Set PintalClosing,這樣就讓一些工具的搜尋功能無法發揮作用。
: If you must use descriptive variable and function names, misspell them. By misspelling in some function and variable names, and spelling it correctly in others (such as SetPintleOpening SetPintalClosing) we effectively negate the use of grep or IDE search techniques. It works amazingly well. Add an international flavor by spelling tory or tori in different theatres/theaters.

4. Be Abstract用抽象的字
在功能及變數的命名上用一些抽象的字,如it, everything, data, handle, stuff, do, reoutine, perform及數字如routineX48, PerformDataFunction, DoIt, HandleStuff and do_args_method等。
: In naming functions and variables, make heavy use of abstract words like it, everything, data, handle, stuff, do, routine, perform and the digits e.g. routineX48, PerformDataFunction, DoIt, HandleStuff and do_args_method.

5. A.C.R.O.N.Y.M.S.用縮寫
用縮寫字讓程式更精簡。真正的男子漢不用解釋這些縮寫, 因為他們生下來就懂得這些字。
: Use acronyms to keep the code terse. Real men never define acronyms; they understand them genetically.

譯者註 :
命名(naming)不清楚是每個程式設計師都會犯的錯誤 (不要告訴我,真正的男子漢生下來就懂得如何正確的命名) ,因此此部分共用32點錯誤的命名方式,前五點如本文就是說,
a.不要用姓名命名
b.不要用單一字母命名
c.不要用錯別字命名
d.不要用抽象字命名
e.不要用縮寫字命名 (沒有人天生就懂)
(2005/01/03 Fred)

相關文章

如何寫出無法維護的程式- 簡介
如何寫出無法維護的程式- 基本原則
如何寫出無法維護的程式- 命名1-5
如何寫出無法維護的程式- 命名6-10
如何寫出無法維護的程式- 命名11-15

如何寫出無法維護的程式 - 基本原則

基本原則General Principles
原作 : How To Write Unmaintainable Code ©1997-2004 Canadian Mind Products
中譯 : Fred F.M. Wang 2005/1/3

Quidquid latine dictum sit, altum sonatur.
Whatever is said in Latin sounds profound.

要搞垮維護程式設計師, 就要先了解他在想什麼. 他有你龐大的程式且他沒有時間全部讀完並了解這些程式. 他要快速的找到他要改的地方, 並確定沒有因為更改而產生額外問題並順利上線
To foil the maintenance programmer, you have to understand how he thinks. He has your giant program. He has no time to read it all, much less understand it. He wants to rapidly find the place to make his change, make it and get out and have no unexpected side effects from the change.

他檢視你的程式猶如看廁所的捲紙筒, 一次只能看到程式的一個小片段. 你要讓他無法得到程式的全貌. 你儘可能的讓他很困難的才可以找到他要找的程式. 更重要的是, 你要讓程式儘可能笨拙的讓他忽略掉一些重要的部分
He views your code through a toilet paper tube. He can only see a tiny piece of your program at a time. You want to make sure he can never get at the big picture from doing that. You want to make it as hard as possible for him to find the code he is looking for. But even more important, you want to make it as awkward as possible for him to safely ignore anything.

程式設計師會習慣於某些設計慣例, 但是你可以在程式每隔一段程式就偷偷的違反這個慣例, 迫使他必須仔細的檢視每一行程式
Programmers are lulled into complacency by conventions. By every once in a while, by subtly violating convention, you force him to read every line of your code with a magnifying glass.

你可以根據不同語言的特性, 洽當的誤用這些特性, 就可以創造出無法維護的程式
You might get the idea that every language feature makes code unmaintainable -- not so, only if properly misused.

譯者註 :
系統開發者往往不能考慮到程式未來的可維護性,導致程式維護成本龐大,製造出更多的問題,而開發專案進行過程往往以結案為第一要務,常常未設定程式設計標準或違反標準或慣例,甚至尚未完全了解程式語言的特性就草草開發,造成錯用,例如Java繼承機制的錯用等。因此程式設計師除了熟悉程式語言外,也要有紀律的遵循程式設計標準或慣例,並研究好的程式設計方法,如Design Patterns, Refactoring等。 (2005/01/03 Fred)

相關文章
如何寫出無法維護的程式- 簡介
如何寫出無法維護的程式- 基本原則
如何寫出無法維護的程式- 命名1-5
如何寫出無法維護的程式- 命名6-10
如何寫出無法維護的程式- 命名11-15
如何寫出無法維護的程式- 命名16-20

如何寫出無法維護的程式 - 簡介

如何寫出無法維護的程式

原作 : How To Write Unmaintainable Code ©1997-2004 Canadian Mind Products

中譯 : Fred F.M. Wang 2005/1/3

簡介Introduction
Never ascribe to malice, that which can be explained by incompetence.

拿破崙Napoleon
這篇論文像冰糖跟糖用線綁在一起然後泡在糖水內, 很快的大到無法收拾
This essay has been like rock candy, seed the string with sugar, soak in sugar water, soon it grew out of control.

為了得到Java程式設計師的聘僱機會, 我寫了這些技巧給雇主有關如何讓寫出來的程式難以維護, 而這些維護者必須跟在你旁邊幾年才有辦法做最簡單的修改. 更進一步你若虔誠地遵循這些規則, 你可以確保終身被雇用, 因為除了你以外, 沒有人希望進入維護程式的煉獄. 另外, 如果你虔誠地遵循這全部的規則, 甚至連你自己都可能無法維護這些程式.
In the interests of creating employment opportunities in the Java programming field, I am passing on these tips from the masters on how to write code that is so difficult to maintain, that the people who come after you will take years to make even the simplest changes. Further, if you follow all these rules religiously, you will even guarantee yourself a lifetime of employment, since no one but you has a hope in hell of maintaining the code. Then again, if you followed all these rules religiously, even you wouldn't be able to maintain the code!

不要做的太過分. 你的程式不該看起來完全沒有可以維護的希望, 而是只是一定程度的問題. 否則會有被重寫或重構的風險
You don't want to overdo this. Your code should not look hopelessly unmaintainable, just be that way. Otherwise it stands the risk of being rewritten or refactored.

這篇論文分成下面段落(原來各段落為網頁上的連結)
This giant essay has been split into sections to make it faster to load.
a.基本原則General Principles
b.命名Naming
c.偽裝Camouflage
d.文件Documentation
e.程式設計Program Design
f.程式模糊化Coding Obfuscation
g.測試Testing
h.語言的選擇Choice Of Language
i.對付其他人Dealing With Others
j.寫你自己的東西Roll Your Own
k.掌握語言的弱點Tricks In Offbeat Languages
l.混雜的技術Miscellaneous Techniques
m.哲學Philosophy
n.沒有鞋的鞋匠The Shoemaker Has No Shoes
o.貢獻者Contributors
p.運作白蟻Operation Termite

譯者註 :
這篇文章用反諷的方式來寫不好的程式設計風格,也就是一個好的程式設計師不該犯的錯誤及該反省是否犯了這些錯誤,藉由這篇文章將自己長久的惡習加以修正。 (2005/01/03 Fred)

相關文章
如何寫出無法維護的程式- 簡介
如何寫出無法維護的程式- 基本原則
如何寫出無法維護的程式- 命名1-5
如何寫出無法維護的程式- 命名6-10
如何寫出無法維護的程式- 命名11-15
如何寫出無法維護的程式- 命名16-20