Thursday, August 31, 2006

8 Basic Programming Techniques v6

8 Basic Programming Techniques v6

List of updated items (quick notes: -- Why I am so pedantic or “academic”? I am writing a big book ;-) – this blog is my high level notes -- I need to keep it clear, always!)

1. Added content of “Three goals for architecture design” to each of the three sections
2. Added content of “three common features for any systems or applications” to each of the three sesctions.
3. Changed the heading “High Level Architecture Reading” to “Higher Level Architecture Reading and Lower Level Skills”, and added “(OO) design patterns, generics, AO design patterns” to it.



==============================8 Basic Programming Techniques

Key Background Knowledge:

1. Higher Level Architecture Reading and Lower Level Coding Skills

Those 8 techniques are described in a top-down style – I assume there is only one (basic) “architecture”, and you know THE architecture. I know it is unusual that we need to talk about THE “architecture” before we talk about the “basic” techniques. Actually, that is NOT that “unusual” -- without knowing those architecture diagrams, a programmer is working in the dark. Again, note that there are many diagrams, but they all convey the same basic architecture.

Reference diagrams from Sun (“Core J2EE patterns”) , Ejb community (“EJB Design Patterns”), and MS-MSDN best practice (“application architecture”):

http://java.sun.com/blueprints/corej2eepatterns/

http://www.theserverside.com/tt/books/wiley/EJBDesignPatterns/index.tss)

http://msdn.microsoft.com/practices/topics/arch/default.aspx?pull=/library/en-us/dnbda/html/distapp.asp


In addition to the above, we also need low level coding skills, i.e., “(OO) design patterns, generics, AO design patterns”.


2. General Reading

Computing changes fast; therefore, experience alone is not enough. Learning through hand-on experiences is not enough. Attending conferences, user groups, and training classes is necessary. However, the most important means is through reading (including listening/watching videos, of course).

Because reading is so important, and because it is so intensive and lasts so long for computing career, it is actually not as simple as it sounds – there are many things need to be continuously pay attention to: how to make notes, how fast is the reading, how close the reading with the daily work, how close the reading with some hand-on experiments, how to find materials, structured or non-structured (e.g. blogs ;-), how to buy those materials, etc.

-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
---------8 Basic Programming Techniques per se
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------


----------------------backend techniques
----------------------The only thing I can argue about grouping logging with databases, is that for a long time, I always put them together. Perhaps it is because the most important logging is database access logging; perhaps it is because logging is somehow similar to database anyway. Note that the second logging in the middle-end is different from the first logging in the backend. The second one is focusing on the “aspect” aspect of it (the “client-side” of the logging); the first one is on the logging itself (i.e., the “server-side” of the logging).
----Separation between database access and business logic (“Three goals for architecture design”)
----Reliable and flexible SECURITY-AUDITING(it is code-based, i.e. not database system based)("three common features for any systems or applications")

1. Use log4net, in a simplistic style (avoid fancy stuff)
2. Use MS Ent Lib’s data access block
2’. Use Nhibernate, instead of Ent Lib, when we are in “advanced” situations

----------------------middle-end techniques
3-4-5-6. Use the DynamicProxy in castle framework to centralize remoting(3), transaction handling(4), security(5), and logging(6), at the façade level.
----Separation between cross-cut concerns and business logic.(“Three goals for architecture design”)
----Reliable and flexible SECURITY-AUTHORIZATION ("three common features for any systems or applications")

Note 1: This is aop and we need to use emit to do it. Note that this removes a lot of needs for coding-time code generation via tools like codesmith. Another side of it is the snippet in IDE. Note that there are other timing choices for code-generation, like asp.net. Coding time code generation is a very powerful tool for programmers. However, it should not be used as a "fix" for architecture design problems – generated repeating code is still duplicated code. In short, declarative programming is the way to go; and it requires code-generation; we need a whole range of timing choices do that, from language build-in to runtime manipulation.

Note 2: In order to do that, Use programmatic IoC (i.e., centralize all “Factories”); but for most projects, do not use XML style IoC (that is too heavy)

--- to avoid client casting, use factoryMethod
--- use abstrctFactory for switching easily
--- put class name, method name, variable name in the factoryMethod


----------------------front-end techniques
----------------------You may ask: why you put unit testing in the front-end group? Reason: I could put it in the middle-end. However, for a long time in my mind, it has always been in the front-end group, perhaps for two reasons: (a) it is an alternative of the UI code; (b) its very existence depends on the diligence of keeping UI code thin and clean -- remember, I do not believe in unit testing UI code -- that is the next generation stuff; not nowadays everyday practice.
----Separation between UI and business logic (“Three goals for architecture design”)
----REGRESSION TESTING (scripted testing, automated testing).("three common features for any systems or applications")


7. The above security and logging can be at property level (i.e. "entity" level, instead of "facade" level or "data access logic" level);
7'. Use the custom class business rule validation technique in CSLA; but via AOP (see above about AOP, but at property level).
7''. Use the “custom class databinding” technique in CSLA; but via AOP (see above about AOP, but at property level).
--- class-to-form using custom event
--- form-to-class (onchange; no exception in set; use rule)

--- tip: listview/read-only-grid read-only: this is good for user anyway;
so, no need of typed collection (note: sorting etc are control's business)
--- tip: update's return object: only get the seq and update the property
do not try to replace the whole object
--- tip: use read-only properties to "borrow" fields for m-m-like
--- tip: inheritance or parent -- pass reader, tx, parent etc.


--- "CSLA with dynamic proxy/aop":
(a) not limiting to 4 (CRUD) methods;
(b) so, no need of special workflow objects,
(c) so, no need for special “criteria” and “exists” classes.

(d) At property level, cleaner property/get/set,
because no CanRead/WriteProperty, PropertyHasChanged calls.

(there is more background info in this blog:
http://www.blogger.com/comment.g?blogID=26752431&postID=115078085354288833
)


--- leverage the full power of the “custom class” in the age/context of “SOA”:
Javascript subset C# to Javascript translator. The good news is that I believe I found it in Ajax framework community.



8. Use Nunit, but only on façade methods.

8'. 3-in-1 document writing for Spec, Test script (Fit or Fit-like), and User Manual: Unit testing is the pivot in all development activities. However, that is easy to say than do. To get that done in a smooth and controlled manner, we need to take a larger perspective, hence this item. For details, please read my related blogs.

---- Note this does not mean this 3-in-1 document writing takes away the pivotal position of unit testing. Unit testing is still the king – from a developer’s biased/tunneled perspective anyway :-)

---- Also note that by this small step, we are combining XP (TDD) with RUP/UP/ISO 9000/SOX. Because the key idea of the latter is “document driven”; and “3-in-1 document writing” is “document driven”. I really believe that in the electronic world, when we routinely take notes in Word (OK, or “StarOffice”? – actually I take notes using VIM, so, do not flame me for being M$ centric) and emails, there is no justification to use those story cards or ORC cards or pieces of napkin anymore – although they sound romantic. In other words, we can expand this further: taking electronic notes is one of the eight basic programming techniques. I know it sounds craze; however, and take some observation yourself:

In meetings, how many people are taking notes using a paper notebook? I guess it will still take a while for us to use a notebook computer, a tabletPC, or, a smaller PDA, or, just use the “old” technique that use a piece of paper and then later put the notes into a computer. The latter practice requires discipline; but it works. Regardless, if you really think about it, contrary to what XP/TDD tells us, those paper notes are not and cannot be simply thrown away; as a result, those paper notebooks are at least one of the sources of unagility.

Rethink design patterns, Generics patterns, and AO design patterns

We need to re-visit, re-think, and re-learn design patterns. As a matter of fact, because “design patterns” are actually only “object oriented design patterns”, so, we need expand it with “generics design patterns”. Further, we need to expand design patterns with “aspect oriented design patterns” as well.

OO, Generics, and AO are all “design patterns”. By “design patterns” I mean the “immediately-close-to-coding design level”. For modern higher level languages (Java, C#, VB.net, even modern C++), for all practical purposes, this level is inseparable from “coding level” itself.

For AO, because of the difficulty of "emit", the basic goal is to recognize aspects and implement those aspects with strict (mechanic) conventions.

For Generics, the goal is to know typical generic usage patterns and the variations of design patterns when they are used with generics.

Because they are low level skills, they must be the second nature of any good programmers. Also, they must have “idioms” with a specific platform; however, the “sense” of it is transferable among modern higher level languages (Java, C#, VB.net, and C++ to a certain degree).

This is the reason that I have this blog:
http://survic.blogspot.com/2006/08/think-in-generics-generics-patterns.html

You may say, give me the “source” -- OK, here is a more definitive source:

http://www.amazon.com/Modern-C++-Design-Programming-Patterns/dp/0201704315/sr=1-1/qid=1157085254/ref=pd_bbs_1/104-9385502-1141540?ie=UTF8&s=books

You are right, the above link is about C++. I understand that C# (.net) is different from C++ (unmanaged), and C# (.net) generics is not “template meta-programming”; however, the idea is the same: we need to think in OO design patterns, generics, and aspects (which is indeed a form of meta-programming).

think in generics: generics patterns, and design patterns with generics

Here are links to help think in generics, generics patterns, and design patterns with generics


------CSLA generics
http://www.rockfordlhotka.org/WeBlog/PermaLink.aspx?guid=10eb26b4-f52d-4ea9-9cb8-ac8c103ee1f2

http://forums.lhotka.net/forums/thread/5168.aspx


------Curiously Recurring Generic Pattern
http://www.artima.com/forums/flat.jsp?forum=106&thread=133275


-----Factory and generics

http://weblogs.asp.net/pgielens/archive/2004/07/01/171183.aspx

http://weblogs.asp.net/gmilano/archive/2005/07/29/420980.aspx



---------------------------------------
(I copy some code here for later reference; they do not have any comments; so, please go the above link for original thoughts)



public interface NoCastCloneable extends Cloneable
{ public T clone();
}

public class NoCastCloneableImpl implements NoCastCloneable {
public NoCastCloneableImpl clone()
{
return (NoCastCloneableImpl)this.clone();
}
}

--------------------------added here because comments cannot have !!

Another piece of code, from Jeffrey Richter’s “CLR via C#” (not from Tod Golding “Professional .Net 20 Generics – which is a “five star” book, but can be better to include “generics design patterns”)

Again, please refer to the original books! I put the code here for my later reference – I am gradually clearing up my notes.

------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication2
{

/// you want all elements the same exact type T
/// or its subtype
/// but why we do not want to similar thing:
/// array of subclass is a subclass of array of class
/// (note: in java this is not the case; C# "fixed" it
/// but now generics it is "broken" again
///

public sealed class Node
{
public TType m_data;
public Node m_next;
public Node(TType data) : this(data, null)
{
}

public Node(TType data, Node next)
{
m_data = data;
m_next = next;
}

public override string ToString()
{
return m_data.ToString() +

((m_next != null)? m_next.ToString():null);
}

public static void TestIt()
{
Node head = new Node ('C');
head = new Node('B', head);
head = new Node('A', head);
MessageBox.Show("" + head.ToString());

}

}

/////////////////////////
public class Node2 {
protected Node2 m_next;

public Node2(Node2 next)
{
m_next = next;
}
}

public sealed class Node3 : Node2
{
public T m_data;


public Node3(T data): this(data, null)
{
}

public Node3(T data, Node2 next) :base(next)
{
m_data = data;
}

public override string ToString()
{
return m_data.ToString() +

((m_next != null) ? m_next.ToString() : null);
}

public static void TestIt()
{
Node2 head = new Node3('.');
head = new Node3(DateTime.Now, head);
head = new Node3("today is ", head);
MessageBox.Show("" + head.ToString());

}

}


}




---------------------------

using System;
using System.Collections.Generic;
using System.Text;

namespace PaulGielens.Patterns.Creational
{
public abstract class Vehicle
{
protected string name;
protected string type;

public Vehicle()
{
}

public Vehicle(string name)
{
this.name = name;
}

// a person who bought my car wants to change its name, unless
public string Name
{
get { return name; }
set { name = value; }
}

// but can't change it's type
public string Type
{
get { return type; }
}
}

// a concrete vehicle
public class Car : Vehicle
{
public Car() : base()
{
}

public Car(string name, string type) : base(name)
{
base.type = type;
}
}

interface IVehicleFactory
{
T CreateObject(string name) where T : Vehicle, new();
}

public class VehicleFactory : IVehicleFactory
{
public T CreateObject(string name) where T : Vehicle, new()
{
// create instance of Type T where this type derives from Vehicle
T v = new T();
v.Name = name;

return v;
}
}

public class FactoryPatternUsingGenericMethod
{
static void Main(string[] args)
{
IVehicleFactory f = new VehicleFactory();
Car c = f.CreateObject("Kitty");
}
}
}
---------------------------------------

public interface IFactory
{
T Create();
}

public class Factory : IFactory where T : new()
{
public T Create()
{
return new T();
}
}
----------------------------------------


public interface IFactory
{
T Create();
}

public class Factory : IFactory where T : new()
{
public T Create()
{
return new T();
}
}
-----------------------------------------

public interface ICar
{
string Name { get; }
}

public class Ford : ICar
{
#region ICar Members

public string Name
{
get { return "Ford"; }
}


#endregion
}

public class Fiat : ICar
{
#region ICar Members

public string Name
{
get { return "Fiat"; }
}

#endregion

}

-----------------------------------------


public interface IFactory where K : IComparable
{
T Create();
}


public interface IFactoryElement
{
object New();
}


public class FactoryElement : IFactoryElement
where T : new()
{

public object New()
{
return new T();
}

}

public class Factory : IFactory where K : IComparable
{
/// Elements that can be created
Dictionary elements = new Dictionary();

///
/// Add a new creatable kind of object to the factory. Here is the key with the beauty of the constrains in generics. Look that we are saying that V should be derived of T and it must be creatable
///

public void Add(K key) where V : T, new()
{
elements.Add(key, new FactoryElement());
}

public T Create(K key)
{
if (elements.ContainsKey(key))
{
return (T) elements[key].New();
}
throw new ArgumentException();
}
}



public class CarFactory
{
Factory internalFactory = new Factory();

public class CarFactory()
{
internalFactory.Add("fiat");
internalFactory.Add("ford");
}

public ICar Create(string carType)
{
return internalFactory.Create(carType);
}
}

------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
---------------------more Links for generics design patterns


----1. http://www.lrde.epita.fr/dload/papers/coots01.html

There are many other papers (C++ and academic) in:
http://www.lrde.epita.fr/cgi-bin/twiki/view/Publications/Papers
especially:
http://www.lrde.epita.fr/dload/papers/europlop00/index.html
http://www.lrde.epita.fr/cgi-bin/twiki/view/Publications/200310-MPOOL


----2. http://www.codeproject.com/cs/design/GenericSingletonPattern.asp

----3. http://www.dofactory.com/Patterns/Patterns.aspx : this one is commercial, I do not know whether they have what they claim that they have. I am not sure… but put the link here anyway.

---------------------------------------
---------------------------------------
---------I have posted the following before, but I am putting them together here (I do not copy the code -- the code was only for backup purpose anyway)
http://survic.blogspot.com/2006/08/think-in-generics-generics-patterns.html

Note that generics and inheritance is interesting:

a. CLR via C# by Jeffrey Richer about moving generics out of inheritance:

Node and TypedNode:Node

b. Andrei Alexandrescu’s Modern C++ Design suggests using “policy”, which use parameters in the child class as the parent(s) – but it needs C++ multiple-inheritance to be a general mechanism; also, by itself, it is not possible in .Net.

c. The “Curiously Recurring Generics Pattern” use parameters in the parent class as the child class. This is especially interesting when you see that “parent” is just an interface (see the last example in the link http://www.artima.com/forums/flat.jsp?forum=106&thread=133275 ).

d. /// array of subclass is a subclass of array of class/// (note: in java this is not the case; C# "fixed" it/// but now generics it is "broken" again

I checked the Java’s “general tutorial” section “generics and subtyping”, it has explanation why this is the case.
http://java.sun.com/j2se/1.5.0/docs/guide/language/
or directly:
http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf

---------------------------------------
---------------------------------------

----4. (from CSLA) http://www.rockfordlhotka.org/WeBlog/PermaLink.aspx?guid=10eb26b4-f52d-4ea9-9cb8-ac8c103ee1f2

----5. (from CSLA) http://forums.lhotka.net/forums/thread/5168.aspx

----6. Curiously Recurring Generic Pattern

http://www.artima.com/forums/flat.jsp?forum=106&thread=133275

----7. Factory pattern and generics
(note: Andrei Alexandrescu’s Modern C++ Design and the link the top of this post
also have this)

http://weblogs.asp.net/pgielens/archive/2004/07/01/171183.aspx

http://weblogs.asp.net/gmilano/archive/2005/07/29/420980.aspx

http://www.developerdotstar.com/mag/articles/troche_factorychain.html


------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
--------------Books on generics, aop, code generation, and generative programming

1. The title of this blog is about generics and aop. I did not mention “code generation” and “generative programming”, because I cannot put “design patterns” after “code generations”. In other words, my focus is on the "thinking at coding time". However, from literature point of view, “code generation” is definitely in the same line – the same line of “generative programming”. Also, by adding “code generation” and “generative programming”, it is clearer that why “generics” and “aop” are related.

2. Patterns and idioms: Nowadays all languages/platforms are interchangeable: C# and VB.Net are interchangeable; C# and Java are even more so; Java/C# and C++ are very close also. However, there are some "headaches" -- some idiomatic issues must be resolved.

(a) The multiple-inheritance in C++ needs to be simulated or replaced by some mechanisms. This is always a big problem, and sometimes needs a lot of work.

(b) C++ (and Java) generics is a kind of "structured code generation", while .Net is not. So, ideas from C++ generics has to be “digested” by all three things in .Net: generics per se, AOP, and code generation per se. Note that although code generation is very powerful; code generation must be treated as the last resort, for obvious reasons. As a result, as C#/VB programmers, we need to pay attention to using the build-in generics and “emit” techniques (ubiquitous factory pattern plus necessary attributes) to realize the same effects of those powerful ideas.

3. Generics, AOP, and code generation do not require any "frameworks": they are the old plain sweet low-profile “library” approach. It can support any frameworks; it also supports the “no framework” approach.

---------------------------Here is the list

Generative Programming: Methods, Tools, and Applications
(Fun read. You will know the sources of all the catching words! Academic and review book)
http://www.amazon.com/Generative-Programming-Methods-Tools-Applications/dp/0201309777/sr=1-1/qid=1159062124/ref=pd_bbs_1/102-3899147-0464903?ie=UTF8&s=books


C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond
(C++ book; necessary to get the perspective)
http://www.amazon.com/C++-Template-Metaprogramming-Concepts-Techniques/dp/0321227255


Modern C++ Design: Generic Programming and Design Patterns Applied
(C++ book; the corner stone book; read it very carefully)
http://www.amazon.com/Modern-C++-Design-Programming-Patterns/dp/0201704315


C++ Templates: The Complete Guide
(C++ book; its chapters on "design" are especially useful)
http://www.amazon.com/C++-Templates-Complete-David-Vandevoorde/dp/0201734842/ref=pd_sim_b_5/102-3899147-0464903?ie=UTF8

-------------
AspectJ in Action: Practical Aspect-Oriented Programming
(java book; however, it is the best aop book. After reading it, you can look into .Net's Castle)
http://www.amazon.com/AspectJ-Action-Practical-Aspect-Oriented-Programming/dp/1930110936/sr=1-1/qid=1159063248/ref=pd_bbs_1/102-3899147-0464903?ie=UTF8&s=books

------------

Code Generation in Action
(using ruby, with a java perspective)
http://www.amazon.com/Code-Generation-Action-Jack-Herrington/dp/1930110979/ref=pd_sim_b_4/102-3899147-0464903?ie=UTF8


Code Generation in Microsoft .NET
http://www.amazon.com/Generation-Microsoft-NET-Kathleen-Dollard/dp/1590591372/ref=pd_sim_b_4/102-3899147-0464903?ie=UTF8

Why delegate is better than interface – in some situations

I know the mechanics of delegate, but I do not really “appreciate” it: I always ask myself: why I should use delegate, instead of interface?

Here is the answer:
http://www.artima.com/intv/simplexity2.html

Basically, if you delegates, it means the signatures are the same; this “coincide” with that convention that when you use delegates, always use the same signature – do not be creative – it all make sense now: delegates/events are simple and mundane “interfaces” -- just like “properties” are get/set methods, which is mentioned in http://www.artima.com/intv/simplexity3.html


C# cleaned up Java’s get/set and simple interfaces, and that is the difference between “class programming” and “component programming”, in simple terms.

Saturday, August 26, 2006

Why MVC is so confusing

I read vikas's blog: http://vikasnetdev.blogspot.com/2006/08/is-3-layered-architecture-mvc.html , which links to http://forums.asp.net/thread/1379168.aspx

This prompts me to think about why MVC is so confusing:

1. First of all, the difference between “design pattern” and “architecture pattern” is well-known; however, the difference between “architecture pattern” and “application pattern” is not well-known/well-established. Actually I feel the latter difference is a misleading concept: if I have a web application, then, should its architecture consult “application patterns” or “architecture patterns”?

I know the source where it comes from -- the SOA. A lot of people believe that SOA is an “architecture pattern” or “system pattern”, and because a “service” is not an “application”, so, a “service architecture” is different from an “application architecture”.

I do not believe so. Service is just a more flexible façade – usually is more coarse-grained and sometimes is async -- in the well-known three-layer application/system architecture. Web is different from Winform, however, we have the same three-layer (or n-layer) application/system architecture. Web service is just a glorified cgi (web). Sometimes, I feel that if those web service people had some hand on experiences with C/Perl (i.e. low level) CGI, then, they will really “feel” and “see” that a web service is just, well, a “web” -- why another architecture? Just marketing strategy?

2. Further, MVC is by itself a little confusing. It is in the introduction of the “design pattern” book, but it is not a low level, pure “OO-only”, “design pattern”; it is an “architecture-oriented” pattern. It has strong implication that it is about the UI – which means, if it is a layered architecture (almost always the case nowadays), then, it is within the UI layer. So, in a sense, it “depends” on the architecture, hence, it is “architecture-oriented”.

3. Another reason that MVC is confusing, my experience, is the usage of the word “model” in MVC. A lot of times, “model” means both the “entity” objects and the “façade objects” in layered architecture (why? because “façade” returns “entity”, together they are the “model”); however, “model” also specifically means the “entity” objects. This is confusing, because “controllers” always call “façade” objects and therefore people feel that “controllers” are “façades”, while sometimes “models” also means “façades”.

4. MVC is especially confusing in asp context, is that for asp, it is not easy to do MVC -- even the “worsened” variation (java/j2EE servlet “model 2” – it is “worsened”, not because the fault of java; it is because of http protocol), unless you do your own handler. ASP uses postback, and therefore, is page-bound (i.e., view-bound; i.e., “V” is inherently inseparable with “C”!). If you use code-behind (by the way, 2.0 has somewhat recovered code-inside!), then, the “code-behind” is something page-bound-controller -- but since it is page-bound, i.e., view-bound, so, it is by definition not a “controller” – I know, my previous sentences look like non-sense – that is exactly my point: as an ASP developer, thanks to M$, we are doomed that we cannot use MVC; as a result of that, in the context that we cannot really use it, and if we do not realize that we cannot use it, then, it creates a lot confusion.

5. The last reason that MVC is confusing is that the general idea of MVC can be, well, “generalized”. For example, “model” is like “entity” objects; “controller” is like a “façade” objects. Also, the way we treat “View” means that we should isolate technology from business logic. However, this is only our, well, “generalization”. MVC itself does not mean those things.

Monday, August 21, 2006

.Net project location is not trusted

.Net project location is not trusted


Got this again; time to put it in my notes/blogs.

Usually this happens when the source is on a network computer. However, it also happens when you unzip a file from internet.


Solution: before you unzip it, you must right click it, property, and unblock.

If you use some other unzip software, then, it may unblock it for you, for better or worse.

I finally decide to join safari. Period. Check it out yourself.

http://www.safaribooksonline.com/products/individuals/it_prof.asp

Saturday, August 19, 2006

Every developer needs to know MSI/ORCA, and WIX

Recently, I need to pick up more msi/orca/wix.

Then, I realize that every developer needs to know WIX and ORCA.

1. WIX makes it so easy to treat installation as part of the development. Just as every developer should understand nant/MSbuild, every one should know wix.

2. Further -- Everyone will install something in development -- my goodness, what are in those msi’s!!! I am always scared. This is the core reason that I say, every developer should know msi/orca – of course, for this purpose, wix is optional.

Also, it is easy, even it looks very difficult.

why and how to back up my blogs

---------------why I need to back up my blogs

I need to back up my blog -- I anticipated this, but I did nothing yet.

This is important to me, because I begin to move all my high level notes to my blogs – and I really like the result. It forces me to be honest when I blog, and it forces me to be objective and therefore also honest when I make my notes. It accelerates my thinking, and keeps my thinking “open”.

However, there is a downside, literally: if the blog is down, I am in trouble. Without my notes, i.e., my blogs, I do not even know how to think – I need to check my notes/blogs.

It has already happened once: last week, when I wanted to check my notes, the blog site was down for maintenance, for (just) 30 minutes or an hour (but in the middle of the day) – it scared me.

As I said, I did anticipate the need. I chose google, because I believe it is reliable and will last for a while, at least, so that I can postpone the need for a while.

----------------how to backup my blogs

A. I checked the blog site, found the following:
http://help.blogger.com/bin/answer.py?answer=41447&topic=8911

I do not like the approach; I will not use the approach.


B. IE’s "Synchronize" (add the website to favorite; organize favorite>property>download can limit link levels, and/or whether following outside links).

It saves the site C:\WINDOWS\Offline Web Pages (it is not clear, I global searched my site name to figure this out) -- it is a binary file.

I guess you can always save individual web files (html, jpg etc.) manually from it offline; so, the real thing is to make sure that you have a copy of the IE that you used to save it -- assuming MS will certainly keep the newer version be able to read older versions data file, so, this perhaps is not a big deal.

It is like the outlook archive files for my emails. They are big, and they are in binary, only outlook can read it. However, emails are not supposedly to be kept long anyway: if it is important, save it outside email. However, blogs are important -- it is my high level notes, part of my external brain.

So, it is worth it to give it another try, see below.



C. I need to “mirror" blog site, i.e. recursively retrieve all links from my blog site.

I prepared to try both of the following:

http://www.httrack.com/ ---- I tried

http://www.gnu.org/software/wget/manual/wget.html ---- I did not try this one

The first one works fine; so, I did not try the second one. Also, it seems that wget is not easy to set up.

The nice thing about it is that it reveals that, the “links to this post” (on the bottom-right of the post) links to the “definitive page” (I give it the name), which contains comments. Further, all those “definitive pages” are organized by year and month. So, I only need to pay attention to survic.blogspot.com\2006\04, 05, 06, etc. Within each folder, I have posts like 8-basic-programming-techniques-v5.html, beyond-java-and-ruby-envy.html, etc. I am hoping when I put jpg there, it will be still so neat.


Happy blogging!!

Wednesday, August 16, 2006

three common features for any systems or applications

"Eight techniques" and "three architecture goals" are good, but they are not the best ways to communicate to users and the management. To do that, we need a "simplified feature oriented approach", hence, "three common features" for any systems or applications.



1. REGRESSION TESTING (scripted testing, automated testing).

2. Reliable and flexible SECURITY-AUTHORIZATION.

3. Reliable and flexible SECURITY-AUDITING (it is code-based, i.e. not database system based) .


“Common” implies it is “architecture”; however, “features” means we insist on a “feature-oriented” or “XP style” approach. Note that those features are extremely useful for themselves – they are more ubiquitous than you think; further, those three features will lead to the body of the iceberg -- yes, I am saying they are just the tip: a comprehensive architecture can “naturally” emerge in the process of handling those three features, in an XP style: piece by piece, just do what is absolutely necessary for now, today. How? Because regression testing means pushing all business logic to the business layer, it immediately means custom class (or dataset with strong separation of UI and business layer) and databining. Reliable and flexible security-authorization immediately means centralized security checking, which means AOP façades or even AOP properties. Reliable and flexible security-auditing immediately means wrapping the database access layer.

So, those “three common features” directly lead to “three (architecture) goals” and “eight techniques”.

Because they are “feature oriented”, instead of “architecture oriented” or “technique/technology oriented” I will begin to use them as my top level thinking. This is important when we talk to users or management: users or management do not care “architecture” or “technique/technology”, they only care “features” (and rightly so). As a result, we must constantly train ourselves to use “feature oriented” languages – I guess this is the very core spirit of XP.

Friday, August 11, 2006

Three goals for architecture design

Three goals for architecture design (i.e. three architecture goals):

1. Separation between UI and business logic.
2. Separation between cross-cut concerns and business logic.
3. Separation between database access and business logic.

Note: the eight techniques I talked before are too detailed for high level discussions; so, I reduce them into three, and use more palatable language.

Also note that I am implying “the truth, the whole truth, nothing but the truth”: those three goals are the whole thing, of an architecture design.

Wednesday, August 09, 2006

VB<>C# translator

I am looking for a VB<>C# translator to translate code for whole projects.

Also, I am looking for C# compiler source code, to translate C# into javascript.

I read Rocky’s blog also: http://www.lhotka.net/weblog/VBCConversions.aspx


So, I checked out: http://www.sharpdevelop.net.

I downloaded it, ran it. The translator works for a “hello world”, but it seems it cannot handle new features in VB.net 2.0. It gave me partial class errors and other errors

I did not dig into it further.

I looked around, there are other similar but commercial tools.
http://www.tangiblesoftwaresolutions.com/
http://www.vbconversions.net/

However, their trial version is limited to 1000 lines or 700 lines code per project.

I will stop here for a while. If you have more info, please add your comments.

Sunday, August 06, 2006

How to learn .net 2005

How to learn .net 2005

We need to think/reflect about our learning approaches or techniques, and listing them is the first step.

Here is a list.

1. Make some “example” programs run, with the help of IDE and google. Note that those materials are also used as (the first) part of the structured reading (see below).

2. Videos, training classes, and team’s casual communications. This is especially useful for IDE’s interactive-oriented features, for example, intellisense, code snippet, refactoring, etc.



3. Unstructured reading: similar to materials in 1, but in “casual” time.

4. Structured reading: The most important ones are the online material in 1. In addition to that, there are books.

-------------------------------------programming
----Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries (Microsoft Net Development Series)

----Effective C#: 50 Specific Ways to Improve Your C# (Effective Software Development) (Paperback)

----Professional .NET 2.0 Generics (Programmer to Programmer) (Paperback)

----CLR via C#, Second Edition by Jeffrey Richter (Paperback - Feb 22, 2006)

----Visual C# 2005: A Developer's Notebook (Paperback)

---------------------------------------winform data binding
----Expert C# Business Objects (Books for Professionals by Professionals) (Paperback)
(it is more than just winform and data binding,
so, based on vikas's comment, I list this book under asp also)

----Data Binding with Windows Forms 2.0: Programming Smart Client Data Applications with .NET (Microsoft Net Development Series) (Paperback)

----Windows Forms 2.0 Programming, 2nd Edition

------------------------------------asp
----Expert C# Business Objects (Books for Professionals by Professionals) (Paperback)
(it is more than just winform and data binding,
so, based on vikas's comment, I list this book under asp also -- see above winform)

----Programming Microsoft ASP.NET 2.0 Applications: Advanced Topics (Paperback)

----Professional ASP.NET 2.0 Security, Membership, and Role Management (Wrox Professional Guides) (Paperback)

----Pro Ajax and the .NET 2.0 Platform (Pro) (Paperback)

----Programming Microsoft ASP.NET 2.0 Core Reference by Dino Esposito

----ASP.NET 2.0 Illustrated (Microsoft .Net Development Series) (Paperback)

Beyond java and Ruby-envy

I went to a bookstore. I browsed some books. Accidentally, I picked “Beyond Java”, and I was surprised, and I read almost the whole book, in the store (OK, I will make up the bookstore later).

It was a very short book; and it was an “opinionated” book; and it changed my perspective.

By the way, there is no code, so, you can read it as Beyond C# also.

I thought C# is the natural place that we can combine the positive things from java and classic VB. However, I guess I was wrong.

I forgot classic VB is not the only RAD platform. Perl is also a RAD (not visual RAD though). Note that perl inspired many other languages/platforms (PHP, python, etc.). Those languages/platforms are RAD environments also. Now, “logically” speaking, combining perl and java (and also lisp), we have Ruby.

When I read Beyond Java, I was impressed that a Java web team can switch to Ruby overnight. I guess it can happen to a C# ASP.net development team also; or, we can use the Castle framework -- I guess it is the power of web: I know M$ does not like this; but if you are doing web development, then, you have the freedom to leave M$, and to be productive and know what you are doing, simultaneously.

Ruby on Rails is “data driven“, while using objects. Because it is dynamic and makes AOP-like things very easy (will be easier soon), you can do more complicated things at the necessary spots when they are really necessary.

A healthy dose of Ruby envy is good; it sets a new goal/threshold. Again, we should look more into Castle framework (note: I have no direct connection with Castle developers).

Wednesday, August 02, 2006

8 basic programming techniques v5

List of updated items :

1. I added “Key Background Knowledge”, and put “Architecture Reading” under it, and also added “General Reading”.

2. I added a "Note 1" in the "middle-end techniques" for aop and emit.

==============================8 Basic Programming Techniques

Key Background Knowledge:

1. Architecture Reading

Those 8 techniques are described in a top-down style – I assume there is only one (basic) “architecture”, and you know THE architecture. I know it is unusual that we need to talk about THE “architecture” before we talk about the “basic” techniques. Actually, that is NOT that “unusual” -- without knowing those architecture diagrams, a programmer is working in the dark. Again, note that there are many diagrams, but they all convey the same basic architecture.

Reference diagrams from Sun (“Core J2EE patterns”) , Ejb community (“EJB Design Patterns”), and MS-MSDN best practice (“application architecture”):

http://java.sun.com/blueprints/corej2eepatterns/

http://www.theserverside.com/tt/books/wiley/EJBDesignPatterns/index.tss)

http://msdn.microsoft.com/practices/topics/arch/default.aspx?pull=/library/en-us/dnbda/html/distapp.asp


2. General Reading

Computing changes fast; therefore, experience alone is not enough. Learning through hand-on experiences is not enough. Attending conferences, user groups, and training classes is necessary. However, the most important means is through reading (including listening/watching videos, of course).

Because reading is so important, and because it is so intensive and lasts so long for computing career, it is actually not as simple as it sounds – there are many things need to be continuously pay attention to: how to make notes, how fast is the reading, how close the reading with the daily work, how close the reading with some hand-on experiments, how to find materials, structured or non-structured (e.g. blogs ;-), how to buy those materials, etc.

-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
---------8 Basic Programming Techniques per se
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------


----------------------backend techniques
----------------------The only thing I can argue about grouping logging with databases, is that for a long time, I always put them together. Perhaps it is because the most important logging is database access logging; perhaps it is because logging is somehow similar to database anyway. Note that the second logging in the middle-end is different from the first logging in the backend. The second one is focusing on the “aspect” aspect of it (the “client-side” of the logging); the first one is on the logging itself (i.e., the “server-side” of the logging).

1. Use log4net, in a simplistic style (avoid fancy stuff)
2. Use MS Ent Lib’s data access block
2’. Use Nhibernate, instead of Ent Lib, when we are in “advanced” situations

----------------------middle-end techniques
3-4-5-6. Use the DynamicProxy in castle framework to centralize remoting(3), transaction handling(4), security(5), and logging(6), at the façade level.

Note 1: This is aop and we need to use emit to do it. Note that this removes a lot of needs for coding-time code generation via tools like codesmith. Another side of it is the snippet in IDE. Note that there are other timing choices for code-generation, like asp.net. Coding time code generation is a very powerful tool for programmers. However, it should not be used as a "fix" for architecture design problems – generated repeating code is still duplicated code. In short, declarative programming is the way to go; and it requires code-generation; we need a whole range of timing choices do that, from language build-in to runtime manipulation.

Note 2: In order to do that, Use programmatic IoC (i.e., centralize all “Factories”); but for most projects, do not use XML style IoC (that is too heavy)

--- to avoid client casting, use factoryMethod
--- use abstrctFactory for switching easily
--- put class name, method name, variable name in the factoryMethod


----------------------front-end techniques
----------------------You may ask: why you put unit testing in the front-end group? Reason: I could put it in the middle-end. However, for a long time in my mind, it has always been in the front-end group, perhaps for two reasons: (a) it is an alternative of the UI code; (b) its very existence depends on the diligence of keeping UI code thin and clean -- remember, I do not believe in unit testing UI code -- that is the next generation stuff; not nowadays everyday practice.

7. The above security and logging can be at property level (i.e. "entity" level, instead of "facade" level or "data access logic" level);
7'. Use the custom class business rule validation technique in CSLA; but via AOP (see above about AOP, but at property level).
7''. Use the “custom class databinding” technique in CSLA; but via AOP (see above about AOP, but at property level).
--- class-to-form using custom event
--- form-to-class (onchange; no exception in set; use rule)

--- tip: listview/read-only-grid read-only: this is good for user anyway;
so, no need of typed collection (note: sorting etc are control's business)
--- tip: update's return object: only get the seq and update the property
do not try to replace the whole object
--- tip: use read-only properties to "borrow" fields for m-m-like
--- tip: inheritance or parent -- pass reader, tx, parent etc.


--- "CSLA with dynamic proxy/aop":
(a) not limiting to 4 (CRUD) methods;
(b) so, no need of special workflow objects,
(c) so, no need for special “criteria” and “exists” classes.

(d) At property level, cleaner property/get/set,
because no CanRead/WriteProperty, PropertyHasChanged calls.

(there is more background info in this blog:
http://www.blogger.com/comment.g?blogID=26752431&postID=115078085354288833
)


--- leverage the full power of the “custom class” in the age/context of “SOA”:
Javascript subset C# to Javascript translator. The good news is that I believe I found it in Ajax framework community.



8. Use Nunit, but only on façade methods.

8'. 3-in-1 document writing for Spec, Test script (Fit or Fit-like), and User Manual: Unit testing is the pivot in all development activities. However, that is easy to say than do. To get that done in a smooth and controlled manner, we need to take a larger perspective, hence this item. For details, please read my related blogs.

---- Note this does not mean this 3-in-1 document writing takes away the pivotal position of unit testing. Unit testing is still the king – from a developer’s biased/tunneled perspective anyway :-)

---- Also note that by this small step, we are combining XP (TDD) with RUP/UP/ISO 9000. Because the key idea of the latter is “document driven”; and “3-in-1 document writing” is “document driven”. I really believe that in the electronic world, when we routinely take notes in Word (OK, or “StarOffice”? – actually I take notes using VIM, so, do not flame me for being M$ centric) and emails, there is no justification to use those story cards or ORC cards or pieces of napkin anymore – although they sound romantic. In other words, we can expand this further: taking electronic notes is one of the eight basic programming techniques. I know it sounds craze; however, and take some observation yourself:

In meetings, how many people are taking notes using a paper notebook? I guess it will still take a while for us to use a notebook computer, a tabletPC, or, a smaller PDA, or, just use the “old” technique that use a piece of paper and then later put the notes into a computer. The latter practice requires discipline; but it works. Regardless, if you really think about it, contrary to what XP/TDD tells us, those paper notes are not and cannot be simply thrown away; as a result, those paper notebooks are at least one of the sources of unagility.