2010年4月24日星期六

部落格搬移

決定要搬家了。
因為blogspot的編輯器沒辦法編輯文字以外的格式,像是XML或程式碼,也顯示不出來,即便手動加上一些tag也沒用。
新家是http://jhcheng.byethost3.com/,除了少數幾篇會搬走以外以外,其他都會留著。

2010年4月23日星期五

Faster Loading Web Pages

似乎是個有用的小技巧,避免網頁花時間在下載javascript內容上。
http://javascript.about.com/library/blfastpage.htm

2010年4月22日星期四

Beginning Microsoft® Visual C#® 2008_Chapter_3_Variables and Expressions

Basic C# Syntax

  1. 一開始程式結構還有註解,跟Java沒啥不一樣,很快過去。
  2. C#有個特殊註解///,Chapter 31會解釋。

Basic C# Console Application Structure

  1. 主程式一樣是static void Main(string[] args)
  2. #region  #endregion 程式碼摺疊起來的時候,可以對該區域做一個註解,這註解會顯示在編輯視窗上面。

Variables

  1. < type > < name > ;

Simple Types

  1. numbers and Boolean
  2. the mechanics of storing numbers as a series of 0s and 1s in the memory of a computer
  3. TypeAlias ForAllowed Values
    sbyteSystem.SByteInteger between – 128 and 127
    byteSystem.ByteInteger between 0 and 255
    shortSystem.Int16Integer between – 32768 and 32767
    ushortSystem.UInt16Integer between 0 and 65535
    intSystem.Int32Integer between – 2147483648 and 2147483647
    uintSystem.UInt32Integer between 0 and 4294967295
    longSystem.Int64Integer between – 9223372036854775808 and 9223372036854775807
    ulongSystem.UInt64Integer between 0 and 18446744073709551615
  4. The u characters before some variable names are shorthand for unsigned
  5. three floating - point variable types: float , double , and decimal
  6. The first two store floating points in the form +/ – m × 2e , where the allowed values for m and e differ for each type.
  7. decimal uses the alternative form +/ – m × 10e .
  8. TypeAlias ForMin MMax MMin EMax EApprox. Min ValueApprox. Max Value
    floatSystem.Single0224-1491041.5 * 10 -453.4 * 10 38
    doubleSystem.Double0253-10759705.0 * 10 -3241.7 * 10 308
    decimalSystem.Decimal0296-2601.0 * 10 -287.9 * 10 28
  9. three other simple types:
  10. TypeAlias ForAllowed Values
    charSystem.CharSingle Unicode character, stored as an integer between 0 and 65535
    boolSystem.BooleanBoolean value, true or false
    stringSystem.StringA sequence of characters

Variable Naming

  1. basic rules:
    • The first character of a variable name must be either a letter, an underscore character ( _ ), or the at symbol ( @ ).
    • Subsequent characters may be letters, underscore characters, or numbers
  2. no keywords
  3. case sensitive

Naming Conventions

  1. Hungarian notation: placing a lowercase prefix on all variable names that identify the type
  2. it is far better to name variables appropriately for their purpose
  3. two naming conventions are used in the .NET Framework namespaces: PascalCase and camelCase .
  4. For your simple variables, stick to camelCase. Use PascalCase for certain more advanced naming, which is the Microsoft recommendation.

Beginning Microsoft® Visual C#® 2008_Chapter_2_Writing a C# Program

前半段介紹Visual Studio跟VCE,不太重要。
接下來是一個小練習,簡單的Console Application。主要目的只是熟悉VCE的環境。
第二個是簡單的Windows Form Application練習。
小心得:
Visual Studio說實在是挺好用的。

Beginning Microsoft® Visual C#® 2008_Chapter_1_Introducing C#

簡單介紹了.NET Framework和C#,以及幾個名詞,像是MSIL、JIT、CLR等,以及程式執行的基本流程。後面有Visual Studio的介紹,不是太重要就不管他了。
小心得:
很多換個名詞後,感覺就是Java哩。當然.NET Framework主要是針對微軟的東西設計的,所以我想細節理當會有很多不同,但以簡介來說,相似度高達90%。

What Is the .NET Framework?

  1. The .NET Framework has been designed so that it can be used from any language, including C# (the subject of this book) as well as C++, Visual Basic, JScript, and even older languages such as COBOL.
  2. .NET - specific versions of these languages have also appeared, and more are being released all the time.
  3. Not only do all of these have access to the .NET Framework, but they can also communicate with each other.

What's in the .NET Framework?

  1. The .NET Framework consists primarily of a gigantic library of code that you use from your client languages (such as C#) using object - oriented programming (OOP) techniques.
  2. Common Type System (CTS)
  3. .NET Common Language Runtime(CLR) : is responsible for maintaining the execution of all applications developed using the .NET library.

Writing Applications Using the .NET Framework

  1. In this book you use VS and VCE for your development
  2. VCE is a slimmed down (and free) version of VS that supports C# only.
  3. For C# code to execute, it must be converted into a language that the target operating system understands, known as native code . This conversion is called compiling code, an act that is performed by a compiler
  4. two - stage process

MSIL and JIT

  1. you compile your code into Microsoft Intermediate Language (MSIL) code.
  2. Just-in-Time (JIT) compiler: compiles MSIL into native code that is specific to the OS and machine architecture being targeted.Only at this point can the OS execute the application.

Assemblies

  1. When you compile an application, the MSIL code created is stored in an assembly .
  2. Assemblies include:
    • executable application files(.exe)
    • libraries(.dll)
    • meta information:information about the information contained in the assembly, also known as metadata
    • optional resources: additional data used by the MSIL, such as sound files and pictures
  3. Global Assembly Cache (GAC):  to place the reusable code in a place accessible to all applications.

Managed Code

  1. Code written using the .NET Framework is managed when it is executed (a stage usually referred to as runtime ).--the CLR looks after your applications by managing memory, handling security, allowing cross - language debugging, and so on.
  2. applications that do not run under the control of the CLR are said to be unmanaged --certain languages such as C++ can be used to write such applications, which, for example, access low - level functions of the operating system.
  3. in C# you can write only code that runs in a managed environment.

Garbage Collection

  1. inspecting the memory of your computer every so often and removing anything from it that is no longer needed
  2. Because this work is done for you at an unpredictable time, applications have to be designed with this in mind.Code that requires a lot of memory to run should tidy itself up, rather than wait for garbage collection to happen, but that isn’t as tricky as it sounds.

Fitting It Together

  1. Application code is written using a .NET - compatible language such as C#
  2. That code is compiled into MSIL, which is stored in an assembly
  3. When this code is executed (either in its own right if it is an executable or when it is used from other code), it must first be compiled into native code using a JIT compiler
  4. The native code is executed in the context of the managed CLR, along with any other running applications or processes

Linking

  1. It ’ s possible to split application code across multiple source code files, which are then compiled together into a single assembly.
  2. This extremely useful process is known as linking

What Is C#?

  1. is one of the languages you can use to create applications that will run in the .NET CLR.
  2. It is an evolution of the C and C++ languages
  3. the language syntax is simpler
  4. those features of C# that parallel the more advanced features of C++, such as directly accessing and manipulating system memory, can only be carried out using code marked as unsafe .
  5. C# being a type-safe language (unlike C++): once some data has been assigned to a type, it cannot subsequently transform itself into another unrelated type.
  6. the only language designed from the ground up for the .NET Framework

2010年4月20日星期二

幾年後的檢視

今天回頭看自己過去寫的這些東西,大部分的撇步其實已經用不上了。隨著這幾年軟硬體的發展,很多問題都已不復存在了,這也是好事。
只是有點小小佩服自己以前竟然肯花這些時間跟精力去解決這些有的沒的小問題,現在工作環境幾乎都是Windows,只能說自己已經很久沒有長進了。
這些小筆記,就留著當作紀念吧。

2009年11月9日星期一

有關梅林的影集

最近突然很想看一些跟魔法有關的片子,自己也不知道為甚麼.總之,就到PPStream上面,找到一部梅林傳奇的影集,想說看看這個全世界最有名的魔法師的故事也不錯.
總之,故事就是以少年梅林初到卡美洛開始,漸漸把其他人物引入.初看一兩集也覺得故事編的還好,不過突然想到我幾年前有買了一本亞瑟王之死的書,想說把他挖出來對照看看.結果一看發現實在是有點驚奇,因為影集的故事和亞瑟王之死簡直天差地別.雖然說亞瑟王的故事本來就有很多神話成分在裡面,不過差這麼多也是有點令人無法接受.
首先是梅林的年代.影集中梅林跟亞瑟幾乎是同年齡的,不過亞瑟王之死開頭講亞瑟的誕生時,梅林已經是一個成名的魔法師了,顯然梅林應該是亞瑟的長輩才對.此外,影集中說亞瑟的父親尤瑟十分痛恨魔法,這跟書中的情節也是差很大,因為梅林一出場就是幫助尤瑟的大魔法師.
第二個大差異是書中明白提到亞瑟是由梅林交付給愛克托爵士養大的,不過影集看到現在雖然還沒有交代這一段,但是顯然是有出路的.因為在書中亞瑟是透過石中劍這個傳說確立起他王國繼承人的身份,而且亞瑟根本也沒見過他老爸,石中劍是他老爸死後發生的事情,拔完劍亞瑟才知道自己真正的身世.但影集一開頭就聲明亞瑟就是王國的繼承人,也沒有引入石中劍,顯然在親子關係的設定上大不同.
再來是其他人物的設定問題,影集跟書本都有很大的差別.先說將來會成為亞瑟老婆的桂尼芬,書中是個國王的女兒,總之也是個王族,不過到影集變成一個女僕.我覺得這實在有點牽强了,要用這樣來塑造亞瑟親民的形象實在有點過頭了,畢竟那個年代根本就不是這樣的.再來是亞瑟的姐姐,書中是同父異母的姐姐,還是個女巫,不過影集變成了養女,會不會變成女巫還不知道,但開頭只是設定成有預知能力,然後因為長的美又跟亞瑟沒有血緣關係,所以亞瑟常常色瞇瞇地看著她.
最後是大名鼎鼎的藍斯洛,影集裡面的設定是個跟亞瑟差不多年紀的平民,假冒貴族想要成為一個騎士.不過我看了書才發現藍斯洛跟愛克托是兄弟,也就是說,藍斯洛本來就是個貴族,而且是亞瑟的伯父輩才對.這點我就真的有點對藍斯洛抱不平了,人家騎士的封號可是正正當當拿到的,根本不是騙來的.
總之,我覺得梅林的成長過程應該是個有趣的題材,因為要養成這樣一個名傳千古的大魔法師,一定有很多故事可以編.不過依照目前流傳的故事內容來看,因為年代的關係,梅林的成長過程顯然跟亞瑟的成長是沒有交集的,影集編劇為了讓大家比較熟悉的亞瑟故事也加進來,硬是把兩個人的年代混在一起,導致其他角色也要跟著變動.基本上個人覺得,神話故事有很多細節是可以變動的,角色的性格等等也可以依照編劇自己的理解去詮釋,但是情節上整個倒轉,我覺得有點不能接受,這就像是把黃帝跟磐古放在一起是一樣的,不知道的人就算了,知道的人就會覺得有點荒謬.不過話是這樣說,這影集也拍到第二季了,顯然還是有不少人看,但對我來說,看到第五集我就有點看不下去了,可能是我比較龜毛吧.