Ray's playground

 

01 2011 档案

Item 18: Distinguish Between Value Types and Reference Types(Effective C#)
摘要:Build low-level data storage types as value types. Build the behavior ofyour application using reference types. You get the safety of copying datathat gets exported from your class objects. You get the memory usage benefitsthat come with stack-based and inline value storage, and you can utilizestand 阅读全文

posted @ 2011-01-27 23:16 Ray Z 阅读(209) 评论(0) 推荐(0)

Item 17: Implement the Standard Dispose Pattern(Effective C#)
摘要:The implementation of your IDisposable.Dispose() method is responsiblefor four tasks:  1. Freeing all unmanaged resources.  2. Freeing all managed resources (this includes unhooking events).  3. Setting a state flag to indicate that the object has been disposed. Youneed to check this state and throw 阅读全文

posted @ 2011-01-27 23:10 Ray Z 阅读(176) 评论(0) 推荐(0)

Item 14: Minimize Duplicate Initialization Logic(Effective C#)
摘要:Here is theorder of operations for constructing the first instance of a type:  1. Static variable storage is set to 0.  2. Static variable initializers execute.  3. Static constructors for the base class execute.  4. The static constructor executes.  5. Instance variable storage is set to 0.  6. Ins 阅读全文

posted @ 2011-01-24 22:33 Ray Z 阅读(185) 评论(0) 推荐(0)

Item 15: Utilize using and try/finally for Resource Cleanup(Effective C#)
摘要:In some ways, resource management can be more difficult in C# than itwas in C++. You can’t rely on deterministic finalization to clean up everyresource you use. But a garbage-collected environment really is much simplerfor you. The vast majority of the types you make use of do not implementIDisposab 阅读全文

posted @ 2011-01-24 21:52 Ray Z 阅读(175) 评论(0) 推荐(0)

Helper Objects (Chapter 6 of Cocoa Programming for Mac OS X)
摘要:Many objects in the Cocoa framework are extended in much the same way. That is, there is an existing object that needs to be extended for your purpose. Instead of subclassing the table view, you simply supply it with a helper object. For example, when a table view is about to display itself, it 阅读全文

posted @ 2011-01-24 18:23 Ray Z 阅读(230) 评论(0) 推荐(0)

Item 13: Use Proper Initialization for Static Class Members(Effective C#)
摘要:Static initializers and static constructors provide the cleanest, clearest wayto initialize static members of your class. They are easy to read and easy toget correct. They were added to the language to specifically address thedifficulties involved with initializing static members in other languages 阅读全文

posted @ 2011-01-22 11:59 Ray Z 阅读(134) 评论(0) 推荐(0)

Item 12: Prefer Member Initializers to Assignment Statements(Effective C#)
摘要:Member initializers are the simplest way to ensure that the member variablesin your type are initialized regardless of which constructor is called.The initializers are executed before each constructor you make for yourtype. Using this syntax means that you cannot forget to add the properinitializati 阅读全文

posted @ 2011-01-21 23:37 Ray Z 阅读(214) 评论(0) 推荐(0)

Creating Output(Chapter 4 of XSLT 2nd Edition)
摘要:In XSLT 2.0, xsl:value-of has a separator attribute. If the select attribute is a sequenceof items, those items are output in sequence, with the value of the separatorattribute between them.  There are some changes to the xsl:number element in XSLT 2.0. First of all, three newformats have been a 阅读全文

posted @ 2011-01-21 10:55 Ray Z 阅读(169) 评论(0) 推荐(0)

Item 11: Understand the Attraction of Small Functions(Effective C#)
摘要:Remember that translating your C# code into machine-executable code isa two-step process. The C# compiler generates IL that gets delivered inassemblies. The JIT compiler generates machine code for each method (orgroup of methods, when inlining is involved), as needed. Small functionsmake it much eas 阅读全文

posted @ 2011-01-18 23:29 Ray Z 阅读(218) 评论(0) 推荐(0)

Item 10: Use Optional Parameters to Minimize Method Overloads(Effective C#)
摘要:Therefore, adding parameters, even if they are optional parameters, is abreaking change at runtime. If they have default values, it’s not a breakingchange at compile time.  Now, after that explanation, the guidance should be clearer. For your initialrelease, use optional and named parameters to crea 阅读全文

posted @ 2011-01-18 21:16 Ray Z 阅读(221) 评论(0) 推荐(0)

XPath: A Syntax for Describing Needles and Haystacks(Chapter 3 of XSLT 2nd Edition)
摘要:There are seven kinds of nodes in XPath:  • The document node (one per document)  • Element nodes  • Attribute nodes  • Text nodes  • Comment nodes  • Processing instruction nodes  • Namespace nodes 阅读全文

posted @ 2011-01-18 21:03 Ray Z 阅读(151) 评论(0) 推荐(0)

Item 9: Avoid Conversion Operators in Your APIs(Effective C#)
摘要:Conversion operators introduce a form of substitutability that causes problems in your code. You’re indicating that, in all cases, users can reasonably expect that another class can be used in place of the one you created. When this substituted object is accessed, you cause clients to work with temp 阅读全文

posted @ 2011-01-16 21:01 Ray Z 阅读(215) 评论(0) 推荐(0)

Item 8: Prefer Query Syntax to Loops(Effective C#)
摘要:C# began as an imperative language. It continues to include all the featuresthat are part of that heritage. It’s natural to reach for the most familiartools at your disposal. However, those tools might not be the best tools.When you find yourself writing any form of a looping construct, ask yourself 阅读全文

posted @ 2011-01-15 10:36 Ray Z 阅读(140) 评论(0) 推荐(0)

Item 7: Understand the Pitfalls of GetHashCode()(Effective C#)
摘要:Summarizing the default behavior, Object.GetHashCode() works correctlyfor reference types, although it does not necessarily generate an efficientdistribution. (If you have overridden Object.operator==(), you can breakGetHashCode()). ValueType.GetHashCode() works only if the first field inyour struct 阅读全文

posted @ 2011-01-15 10:12 Ray Z 阅读(210) 评论(0) 推荐(0)

The Obligatory Hello World Example(Chapter 2 of XSLT 2nd Edition)
摘要:[代码][代码]java -cp saxon9he.jar net.sf.saxon.Transform -t -greeting.xml -xsl:greeting.xsl -o:output.html[代码] 阅读全文

posted @ 2011-01-13 20:13 Ray Z 阅读(190) 评论(0) 推荐(0)

Item 6: Understand the Relationships Among the Many Different Concepts of Equality(Effective C#)
摘要:C# gives you numerous ways to test equality, but you need to consider providingyour own definitions for only two of them, along with supporting theanalogous interfaces. You never override the static Object.ReferenceEquals()and static Object.Equals() because they provide the correct tests, regardless 阅读全文

posted @ 2011-01-12 21:23 Ray Z 阅读(243) 评论(0) 推荐(0)

Target/Action(Chapter 5 of Cocoa Programming for Mac OS X)
摘要:AppController.hCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1#importFoundation/Foundation.h234@interfaceAppController:NSObject5{6IBOutletNSTextField*textField;7NSSpeechSynthesizer*speechSynth;8}910-(IBAction)sayIt:(id)sender;11-(IBAction)stopIt: 阅读全文

posted @ 2011-01-12 09:18 Ray Z 阅读(239) 评论(0) 推荐(0)

Item 5: Always Provide ToString()(Effective C#)
摘要:[代码] 阅读全文

posted @ 2011-01-11 22:37 Ray Z 阅读(182) 评论(0) 推荐(1)

Variables, Scope, and Memory(Chapter 4 of Professional JavaScript® for Web Developers 2nd Edition)
摘要:JavaScript ’ s lack of block - level scopes is a common source of confusion.[代码]  When a variable is declared using var , it is automatically added to the most immediate contextavailable. In a function, the most immediate one is the function ’ s local context; in a with statement, themost immediate 阅读全文

posted @ 2011-01-10 19:55 Ray Z 阅读(196) 评论(0) 推荐(0)

Language Basics(Chapter 3 of Professional JavaScript® for Web Developers 2nd Edition)
摘要:The end result was forECMAScript to provide two sets of operators: equal and not equal to perform conversion beforecomparison, and identically equal and not identically equal to perform comparison without conversion.equalityCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.C 阅读全文

posted @ 2011-01-10 18:55 Ray Z 阅读(201) 评论(0) 推荐(0)

Objective-C(Chapter 3 of Cocoa Programming for Mac OS X)
摘要:[代码][代码][代码] 阅读全文

posted @ 2011-01-10 10:45 Ray Z 阅读(283) 评论(0) 推荐(0)

Item 4: Use Conditional Attributes Instead of #if(Effective C#)
摘要:The Conditional attribute generates more efficient IL than #if/#endifdoes. It also has the advantage of being applicable only at the functionlevel, which forces you to better structure your conditional code. The compileruses the Conditional attribute to help you avoid the common errorswe have all ma 阅读全文

posted @ 2011-01-09 22:31 Ray Z 阅读(242) 评论(0) 推荐(0)

Item 3: Prefer the is or as Operators to Casts(Effective C#)
摘要:Remember that user-defined conversion operators operate only on thecompile-time type of an object, not on the runtime type.  Now that you know to use as when possible, let’s discuss when you can’tuse it. The as operator does not work on value types.  The is operator should be used only when you cann 阅读全文

posted @ 2011-01-09 11:16 Ray Z 阅读(217) 评论(0) 推荐(0)

2011计划
摘要:2011年已经过去一周,月底就要回家过年了,定下计划先.  这次不能像之前那样计划定得太粗,完全没有东西可以准确衡量完成度.  1. 随笔达到600篇,这样算来,每月必须写25篇左右.一年下来,应该会看完至少20本书了.  2. C++, Python, Java应该都算入门了,希望在这一年里能更进一步  3. C++之前囫囵吞枣的看了好多书,但现在想想应该更深入地看一次.  Thinking in C++(60%)  Effective C++/More Effetive C++  The C++ Standard Libray  Windows via C/C++  研究开源项目Mongo 阅读全文

posted @ 2011-01-08 23:15 Ray Z 阅读(265) 评论(0) 推荐(0)

STL Containers & Iterators part1(Chapter 4 of Thinking in C++ Vol 2)
摘要:codeCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1#include<iostream>2#include<vector>3#include<iterator>4usingnamespacestd;56template<classCont,classPtrMemFun>7voidapply(Cont&c,PtrMemFunf)8{9typenameCont::iteratorit= 阅读全文

posted @ 2011-01-08 22:17 Ray Z 阅读(234) 评论(0) 推荐(0)

Item 2: Prefer readonly to const(Effective C#)
摘要:Compile-time constants are limited to numbers and strings. Read-onlyvalues are also constants, in that they cannot be modified after the constructorhas executed.  You can use readonly values for instance constants, storing different valuesfor each instance of a class type. Compile-time constants are 阅读全文

posted @ 2011-01-08 16:57 Ray Z 阅读(201) 评论(0) 推荐(0)

Item 1: Use Properties Instead of Accessible Data Members(Effective C#)
摘要:You can specify different accessibility modifiers to the getand set accessors in a property in C#.  Indexers can be virtual or abstract; indexerscan have separate access restrictions for setters and getters. You cannotcreate implicit indexers as you can with properties.[代码] 阅读全文

posted @ 2011-01-08 16:08 Ray Z 阅读(188) 评论(0) 推荐(0)

Memory Management(Chapter 4 of Cocoa Programming for Mac OS X)
摘要:If you are using the garbage collector, it is important that you not keep references to objects that you don't care about. In the main function of lottery, you should set the now and array pointers to nil when you lose interest in them.[代码]  Objects are added to the current autorelease pool when t 阅读全文

posted @ 2011-01-08 14:24 Ray Z 阅读(221) 评论(0) 推荐(0)

JavaScript in HTML(Chapter 2 of Professional JavaScript® for Web Developers 2nd Edition)
摘要:For pages that require a lot ofJavaScript code, this can cause a noticeable delay in page rendering, during which time the browser willbe completely blank. For this reason, modern web applications typically include all JavaScript referencesin the body element, after the page content.  HTML 4.01 de 阅读全文

posted @ 2011-01-08 13:04 Ray Z 阅读(214) 评论(0) 推荐(0)

What Is JavaScript?(Chapter 1 of Professional JavaScript® for Web Developers 2nd Edition)
摘要: 阅读全文

posted @ 2011-01-08 12:29 Ray Z 阅读(187) 评论(0) 推荐(0)

Let's Get Started(Chapter 2 of Cocoa Programming for Mac OS X)
摘要:[代码][代码] 阅读全文

posted @ 2011-01-07 10:35 Ray Z 阅读(191) 评论(0) 推荐(0)

导航