還記得”Algorithm+Data=Program”嗎?

對於我這個5年級學習資訊科學的人來說,Nicklaus Wirth是不能忘記的偉大軟體科學家,Nicklaus Wirth”Algorithm+Data=Program”這本資料結構的書籍是我大二時在台大圖書館中最常苦讀的書籍(呵呵,當然是因為要應付考試啦)Nicklaus Wirth發明的Pascal程式語言深深的影響了資訊界長達數10年之久,然而隨著最近10年物件導向程式語言成為資訊界程式語言的主流後,要不是Borland/CodeGearDelphi與時併進並且為Pascal加入最先進的物件導向的功能,Pascal也不可能在今日仍然是非常流行的程式語言之一(http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html)Nicklaus Wirth的偉大貢獻最終讓他獲得了Turing Award,算是實至名歸了。

為什麼我要在篇文章中再提到Nicklaus Wirth?因為隨著Delphi
Unicode
的版本的逼近,最近更讓我回想起Nicklaus Wirth”Algorithm+Data=Program”這句話說的真好。最近幾年由於物件導向的流行,因此大部份的開發人員使用了類別,物件,元件等技術封裝運算法則和資料,讓用戶端不必瞭解內部實作的技術,這聽起來和看起來都很棒,但是開發人員如何在內部藉由實作運算法則來處理資料卻仍然可能撰寫使用了非常糟糕的程式碼,有句成語『金絮其外,敗絮其內』可能蠻適切的能夠形容這種情形。例如許多開發人員可能分不清楚什麼是encoding的意義,也分不清楚Lengthsizeof的意義,在許多的情形下也分不清楚陣列中位元組和元素的分別。當然,會造成這些問題的原因是因為大多數的開發人員是從原生程式語言開始寫程式碼,在我們學習BBC的第一步腦中就充滿了位元,位元組,字元的觀念,而從C/C++背景來的開發人員更習於使用指標運算來加速資料存取的速度並且節省程式碼的撰寫。如果你會問腦中有這些觀念或是使用指標存取有什麼問題呢?那麼我們至少可以列出下面的數個問題:

  •   開發人員必須知道++, —等使用在字元指標,整數指標和陣列指標的不同

  •   Windows OS16位元,32位元和64位元,資料型態在這些OS中的大小一樣嗎?

例如下面是一些Delphi程式碼,您可以明確的說出它們的意義或是運算結果是什麼嗎?

 

sdata := ‘IT : 是工作還是嗜好?’;

iLen := Sizeof(sdata);

iLen := Length(sdata);

而如果我使用下面的程式碼存取出的又是什麼結果呢?

sdata := ‘IT : 是工作還是嗜好?’;

for iIndex := 1 to Length(sdata) do

begin

 
ListBox1.Items.Add(sdata[iIndex]);

end;

啊,如果您很認真的思考上面的話,我很抱歉,我故意耍了一個小手段,因為我沒有告訴您sdata的資料型態是什麼,sdata可以是string,也可以是widestring,也可以是AnsiString,不同的資料型態在目前的Delphi中會有不同的結果。例如AnsiString/String是使用reference counting的方式來處理字串資料(faster),而WideString則否(copy on write, slower)。此外使用陣列存取AnsiString/StringWideString的結果也不同。

正是由於OS平台的不同,資料型態的不同,開發人員使用的程式碼不同,讓程式碼中夾雜了許多不具移植性,甚至是可能發生錯誤的程式碼,因此我才說在即使是在物件導向程式技術盛行的今日,別忘了Nicklaus Wirth的公式:

Algorithm+Data=Program

中的Data仍然是整個應用程式中佔有一半的因素,我個人認為Java.NET的好處之一是除了程式碼深具移植性之外,Java.NET平台也讓Data具備了通透性,讓開發人員不再容易寫出可能的錯誤程式碼。Java/.NET虛擬平台讓開發人員享受到資料通透性的好處,那麼原生Windows開發人員也可以嗎?這個意思是說原生Windows開發人員可以在使用指標或是陣列索引的同時又能夠享受到資料通透性的好處嗎? 答案在於編譯器和框架的發展如何!

DelphiC++Builder來說,隨著VCL框架可同時執行於Win16Win32Win64,再隨著Delphi/C++Builder Unicode的版本即將提供資料通透性的能力,再加上Delphi下一版的編譯器中內含helper函式和資料自動轉換的能力,下一版的Delphi/C++Builder將同時提供Java/.NET虛擬平台最大的2項優勢:

程式碼+資料的跨平台通透性

而且加入Java/.NET虛擬平台沒有的優點:

快速的原生執行速度

因此在以前的Delphi/C++Builder版本中AnsiString/String是以如下的結構來實作:

參考數值

長度

資料(以位元組計算)

-8           

-4        

0 

那麼只要未來的Delphi/C++Builder先定義UniCode結構:

代碼頁

參考數值

長度

資料(以位元組計算)

-12

-8           

-4         

0 

再定義:

type
  string = UnicodeString

那麼就可以通透的把string自動改為Unicode資料型態並且可以執行在Win32/Win64平台之中,開發人員也只需要修改最少的程式碼,也就是和處理Data運算有關的程式碼,那麼從此之後開發人員的應用程式就有了資料通透性了。

一旦如此,當您使用:

sdata := ‘IT : 是工作還是嗜好?’;

for iIndex := 1 to Length(sdata) do

begin

 
ListBox1.Items.Add(sdata[iIndex]);

end;

程式碼來存取資料時,就不會是讓人看不懂的:

http://tkfiles.storage.live.com/y1pzGurgrznJM1D5MAG5tzbV1aqIkgUwqNdP-XSSVXjwIHm6iEOwdz_4gZrKRYWUvMAKnX2CBNPKSQ

而是正確的:

http://tkfiles.storage.live.com/y1pzGurgrznJM2umVusiRSdu6vJS6CBBWNa5oedJ7MxOCqzkQP9OSKRflFhZuPETWTXP2kXTc1s2_E

因為資料擁有了通透性,開發人員再不需記住繁瑣的不同的資料型態使用不同的存取方式程式碼了。

未來的Delphi/C++Builder版本再次讓Delphi/C++Builder的開發人員進入了新的世代,當VCL框架/編譯器提供了程式碼+資料的跨平台通透性之後,就為Delphi/C++Builder奠定了未來平行/多核開發的基礎。

”Algorithm+Data=Program”也是歷久彌新啊!

  1. #1 by huancheng on 2008 年 04 月 02 日 - 15:41:07

    李老师终于又露面了,请教DELPHI2008什么时间出来呀?

  2. #2 by James on 2008 年 04 月 02 日 - 18:46:13

    還以為大哥不關心 Delphi 了呢,最近還在研究 ECO IV,想到之後 Delphi Unicode 的版本頭就痛,一堆 3-Party 的 Component 又要死光光了呀~

  3. #3 by on 2008 年 04 月 03 日 - 02:36:46

    >李老师终于又露面了,请教DELPHI2008什么时间出来呀?CodeGear不是早公佈過了嗎, 應該是今年下半年吧.

  4. #4 by on 2008 年 04 月 03 日 - 02:39:09

    >想到之後 Delphi Unicode 的版本頭就痛,一堆 3-Party 的 Component 又要死光光了呀~Unicode是必走的路, 你用的TurboPower有source不用怕, 基本上舊的程式直接用Delphi 2008 compile就可以變成unicode版, 只有一些使用Pointer/Char/memory相關的code要改, CG應該會公佈一份文件告訴開發人員要改那些code.

  5. #5 by ykai on 2008 年 04 月 04 日 - 15:14:27

    还真以为李先生离开D了呢,好久都没更新了这里。
    更想知道的是d2008对wf,wpf和wcf的支持也就是说对.net3.0和3.5的支持程度如何,对WSS/MOSS的支持,是否快速开发和定制,是否有一些相关的开发组件。我觉的这个是非常重要的。就语言来说\u这样的支持相对比较晚了,更好的方式是除delphi外编译器可以在支持某种脚本语言嵌入在代码内,或许这才可以称作强大吧。
    希望CG提供好的容器库,网络库、正则表达式库………如果不能,就让delphi除了可以嵌入汇编,还可以嵌入脚本吧。

  6. #6 by ce on 2008 年 04 月 08 日 - 06:59:10

    //只有一些使用Pointer/Char/memory相關的code要改
    修改这三个很麻烦, CodeGear在编译器上遇上 string 转 Pointer/Char/memory的代码,就直接调用一个函数把unicode转ansistring,再转Pointer/Char/memory, 就样比开发人员转代码方便,原来使用Pointer/Char/memory的代码都是假设为ansistring类型

  7. #7 by wise on 2008 年 04 月 11 日 - 01:02:21

    string = UnicodeString ,不错,简单,这么大的改动,希望codeGear能够先出一个Beta版本,不要正式版一出来就碰上Bug,反而不好,,
     

  8. #8 by Unknown on 2008 年 06 月 24 日 - 12:46:22

    wow gold!All wow gold US Server 24.99$/1000G on sell! Cheap wow gold,wow gold -230665817208785

  9. #9 by Sanny—天地一沙鸥 on 2008 年 09 月 18 日 - 09:08:11

    不記得了,一離校偶就丟了程式,現在做和程式無關的工作!HTML clipboard………………………………………………………

  10. #10 by Unknown on 2008 年 10 月 14 日 - 04:40:39

    It’s rather ffxi gilamazing how fast aoc goldthis innovation is moving. wow goldEven to keep the like of myself who are deeply involved in the in wow golddustry to go and see the improvement and every element that are taking place on a yearly basis is quite fantastic. maple story mesoOf course one of the driving wow goldfactors of this business is the exponential aoc goldincrease in processor performance. There is no doubt that the magic of chip capability has delivered through the advance in wow goldmicroprocessor allows us to think of wow goldapplication which never would have wow goldbeen possible before. The PC industry is wow power levelingone of the few industries that wow goldcan deliver lower price wow goldequipment at the same time as improving wow power levelingthe capabilities. The storage systems are now delivering Gigabyte of storage as the standard capability.Over 80 million of PCs wow goldare being sold a year. maple story mesosAnd the server market, the higher performance machines that these PCs networked with,are the fastest growing part of this business. The performance of twow goldhose servers is increasing not only because processors are faster, but also because we are wow goldusing multiple-processor machines, socalled SMP designs andwow power leveling clustering nodes together… Great chips, systems developers,wow gold partners who are wow goldsponsoring this event, making this all possible. There is an wow goldincredible opportunity for developers. The applications maplestory mesosthat are written today will sell to an even larger base wow goldof machines out in the market. There is a lot that we’re doing to increase the work of good developers-make sure they understand where the PC is going and how wow goldtools can help them now, more and more marketing type of activities making sure they got in with the customers.This is something that we wow goldare going to increase wow power levelingyear after year.

  11. #11 by Unknown on 2008 年 10 月 14 日 - 04:42:14

    dofus kamas kamas dofus dofus kamas kamas dofus dofus kamas kamas dofus dofus kamas kamas dofus dofus kamas kamas dofus wow leveling Runescape Money Runescape Gold Runescape Money Runescape Gold Runescape Power leveling Runescape Money Runescape Gold Runescape gold runescape money Runescape Money Runescape gold Runescape Money Runescape gold Runescape Power leveling Runescape Items runescape money runescape gold money runescape Runescape Money Runescape gold Runescape Gold runescape money age of conan gold aoc power leveling age of conan power leveling aoc leveling age conan gold archlord gold buy archlord gold anarchy online credits anarchy online credit city of heroes influence coh influence city of villains infamy cov infamy dofus kamas kamas dofus eve isk eve online isk everquest 2 gold eq2 plat ffxi gil final fantasy xi gil buy ffxi gil gaia online gold gaia gold guild wars gold gw gold hellgate london palladium cabal alz daoc gold daoc plat world of warcraft gold wow po wow or buy wow gold cheap wow gold wow power leveling wow powerleveling

  12. #12 by Unknown on 2009 年 03 月 04 日 - 07:06:54

    In Maple Story, players will be able to create characters that will grow as they learn new skills and become stronger. There are four characters to choose from: Warriors, Bowmen, Magician, or Thief. These characters can be dressed in many different and colorful outfits. Personalizing characters is one of the goals of Maple Story. Once a character has been created, they will learn skills that will help them when they reach Victoria Island.http://www.cheap-msmesos.comhttp://www.allgametrade.comhttp://www.lotro-shop.comhttp://www.aocgolds.net/

發表留言