Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Wednesday, December 27, 2006

Asynchronous Web Page Programming in ASP.NET 2.0

Asynchronous programming allows a process to have multiple threads, enabling the process to do more than one action simultaneously. While asynchronous programmingcan be complicated, it can dramatically improve performance in situations where the process would otherwise need to wait for a relatively slow action, such as accessing a network resource, to occur.

For example, if you are creating a Web page that must query a network resource (such as a Web service), IIS and ASP.NET can only render a limited number of pages simultaneously.Therefore, the thread pool can become completely consumed, creating a performance bottleneck. Once the thread pool is consumed, your server waits for pages to finish rendering before beginning to process other pages. Even though the server might have available processor cycles, requests are queued. By enabling asynchronousWeb page programming, the server can begin rendering more pages simultaneously,improving efficiency and reducing page rendering time.

Tuesday, October 24, 2006

My Naming Conventions in .NET

^ 我想尽量兼顾VB.NET和C#。

^ Field/Class Variable: Pascal Case。Always indicate Private, do not use Dim.

^ Property: Pascal Case。

^ Parameter: Camel Case。在method body中,定义一个Local Variable,采用Pascal Case命名,除了首字母其他完全一致,然后把parameter赋值给相应的Local Variable。

^ Property和Method是给“外人”看的,命名要“好看”,所以就要规规矩矩地Pascal Case。Field是自己用的,所以命名可以有点儿“特色”。

d Field: Camel Case with Leading Underscore. In VB.NET, always indicate "Protected" or "Private", do not use "Dim".
Of all the items here, the leading underscore is really the only controversial one. I personally prefer it over straight underscore-less camel case for my private variables so that I don't have to qualify variable names with "this." to distinguish from parameters in constructors or elsewhere where I likely will have a naming collision. With VB.NET's case insensitivity, this is even more important as your accessor properties will usually have the same name as your private member variables except for the underscore.


d Properties: Pascal Case, no underscores. Try to avoid abbreviations. Members must differ by more than case to be usable from case-insensitive languages like Visual Basic .NET.
VB: Public Property RecordID As Integer
C#: public int RecordID

d Parameters: Camel Case. Try to avoid abbreviations. Parameters must differ by more than case to be usable from case-insensitive languages like Visual Basic .NET.
VB: ByRef recordID As Integer
C#: ref int recordID

d What are your thoughts on naming conventions that need to be used to distinguish the class variables, function local variables and method arguments?
d By class variables, I assume you mean fields. Those should be private (use properties for public exposure to provide a level of abstraction). For function locals, those are by definition private. For method arguments, those need to be camelCased. For the privates, I have seen two patterns in the .NET Framework: one is leading underscore, and the other is this.Foo. Either works for me.

d However, I then had to do some VB.NET development and the language isn't case sensitive. I've seen some examples that add a "Field" suffix in VB.NET . I think that is worse than a leading "_". So I came full circle and started using "_" again. :)

e Designing .NET Class Libraries: Naming Conventions (January 26, 2005)
e .NET Programming Standards and Naming Conventions

Tuesday, October 10, 2006

Declarative Language V.S. Imperetive Language

@ The ASP.NET markup language (that is, the ASPX language) is increasingly being recognized as a declarative programming language.

@ Declarative programming is quite a different programming model.
@ When you program with an imperative language, you reach a desired goad by providing the specific operations required to reach the goal. (That is, you tell the computer how to reach your goal.)
@ When you program with a declarative language, you specify your goal and a compiler or interpreter uses its predefined algorithms to determine the appropriate operations to reach that goal. (That is, the computer find a way to reach your goal.)

^ 这就像我曾经说过的,我只在乎是否实现了一个function,而不在乎这个function是怎么被实现的。

e The Right Way to do Ajax is Declaratively
e Declarative V.S. Imperative Programming
e Declarative programming
e del.icio.us/tag/declarative

Reflection到底是个啥东西?

@ Code in the CLR is packaged in an assembly. Even though it is often thought of as a file, an assembly is actually a logical container for different parts of the data the CLR needs to execute code.

@ These parts of data of an assembly include: Assembly metadata, Type metadata, Intermediate Language code, and Resources.

@ Assembly Metadata includes data that defined the assembly, such as the name, version, strong name, and culture information. Assembly metadata is also called manifest.

@ Type Metadata is the information describes what a type looks like, including the namespace, class name, members (methods, properties, constructors, etc.), and parameters.

@ Most of the time, all these parts of an assembly are compiled into a single file.

@ Assemblies are containers for modules, and modules are containers for types.

^ 我啥时候会用的上Reflection呀?

e C-sharp reflection: Save development time throughout the project life-cycle

Sunday, September 24, 2006

.NET : Threading

Why and when to use multithreading?

@ For most developers, the primary motivation for multithreading is the ability to perform long-running tasks in the background, while still providing the user with an interactive interface.
Another common scenario is when building server-side code that can perform multiple long-running tasks at the same time, thus, each task can be run on a separate thread, allowing all the tasks to run in parallel.

@ If we regard computer programs as being either application software or service software:
Application software uses multithreads primarily to deliver a better user experience.
Service software uses multithreads to keep CPU busy servicing and deliver scalability.

@ For interactive applications, multithreading is not a way to improve performance, but rather is a way to improve then end user experience by providing the illusion that the computer is executing more code simultaneously.
In the case of server-side code, multihtreading enables higher scalability by allowing Windows to better utilize the CPU along with other subsystems such as IO.

What the fuck is thread?

@ The term thread is short for thread of execution.
When your program is running, the CPU is actually running a sequence of processsor instructions, one after another. You can think of these instructions, one after another, as forming a thread that is being executed by the CPU.

What is process?

@ Each of the programs your computer keeps in memory runs in a single process. A process is an isolated region of memory that contains a program's code and data. The process is started when the program starts and exists for as long as the program is running.

@ When a process is started, Windows sets up an isolated memory area for the program and loads the program's code into that area of memory. It then starts up the main thread for the process. The mean thread might execute instructions taht create more threads within the same process.

Tuesday, September 19, 2006

编程高手是怎样变成的呀?

虽然写了五年程序了,Java,C#,Ruby on Rails,VB.NET,用过好几种语言,也参加过不少大项目的开发,可总是对自己的编程能力不够有信心。虽然,有的程序也写得很好,却好像从没真正全面地掌握一种语言,没能对所有的特性都了然于心。从开始编程,所有的东西都是自学的,也从来没请过高手指导自己,总感觉不是那么“正”。不像在武术领域有大师言传身教,不像在音乐方面有专业演奏家指导。为啥我靠着吃饭的东东却没有请人指导过呢?吼吼!

现在在准备MCPD的认证考试,第一门又是关于语言的,我选择VB.NET作为考试语言,因为我发现VB.NET的语法和Ruby语言很像,都接近英语,少了很多像C#那样的乱七八糟的符号,更符合我这个“人文大脑”的程序员。嘿嘿。毕竟,我在运用人类语言的方面是有灵性的,可一旦到了数理方面,我就成了某人说的呆瓜了。上次考SCJP,考的Java语言,其实这两门考试的内容差不多,涵盖的都是Object-Oriented Programming的东西,只不过用了两套不同的语言语法而已,思想上没有啥大区别。上次以83%通过的,这次也不会是问题。

复习考试,不求一遍能够完全明白,多看几遍,多做些题,量变成质变。有些语言特性可能自己不理解,但是目前做到知道怎么答题就行了。有用的东西都记录下来,发布在这个Blog上,方便自己以后回来查阅。不懂的地方,就多请教人家,即便是有嘲笑,有脸色,忍了,反正不是我没素养。哈。有机会的话,请一位公司里的编程高手指导一番,咱也提升提升水准。希望在我离开这个行业之前成为一个编程高手,否则总有些逃兵的感觉。

王者之程(程序的程,嘿嘿)