
I have found a very funny flow diagram on xkcs. In this diagram non-computer people gets some instructions what do to when they getting an error on the pc BEFORE calling 'computer experts'.
You are running into a feature referred to as 'Solution Root' added
to VS2003 (and carried forward into VS2005). You can disable this behavior
via the following registry entry:
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\SourceControl\DoNotCreateSolutionRootFolderInSourceControl
Difference Between Builder pattern and Factory pattern
The factory pattern defers the choice of what concrete type of object to make until run time. E.g. going to a restaurant to order the special of the day. The waiter is the interface to the factory that takes the abstractor generic message "Get me the special of the day!" and returns the concrete product (i.e. Hawaiian or Spicy pizza)
The builder pattern encapsulates the logic of how to put together a complex object so that the client just requests a configuration and the builder directs the logic of building it. E.g The main contractor (builder) in building a house knows, given a floor plan, how to execute the sequence of operations (i.e. by delegating to subcontractors) needed to build the complex object. If that logic was not encapsulated in a builder, then the buyers would have to organize the subcontracting themselves ("Dear, shouldn't we have asked for the foundation to be laid before the roofers showed up?")
The factory is concerned with what is made, the builder with how it is made. Design patterns points out that Abstract factory is similar to builder in that it too may construct complex objects. The primary difference is that the Builder pattern focuses on constructing a complex object step by step. Abstract factory's emphasis is on families of product objects (either simple or complex). Builder returns the product as the final step, but as far as the Abstract Factory is concerned, the product gets returned immediately.
<a onclick="window.open(this.href,'_blank');return false;" href="http://some_oother_site.com">Some Other Site</a>
new public virtual string TemplateSourceDirectory
{
get
{
return Page.TemplateSourceDirectory;
}
}
<meta http-equiv="X-UA-Compatible" content="IE=7" />
The usage of String.Empty is more efficient that the usage of empty quotes.
When using empty quotes an object is created and this produces more assembly code on the execution stack and for string.Empty is NO object created.
The usage of String.Length == 0 is the best. Now there is a numeric compare applied instead of a string compararision, and numeric compare is quicker.
Only what if the string has the value null? So use string.IsNullOrEmpty method
More info: C# Shiznit, Vikram's Blog
In Coding Standards is the differents between throw and throw e explained.
What is the difference?
The difference is that 'throw;' the original stack trace persists and 'throw ex' truncates the stack trace after the method where the 'throw ex;' is called.
When using 'throw;'?
When in the try{...} a method is called then you must use 'throw;' to take care that you have the original stack trace.
Example:
// Bad!
catch(Exception ex)
{
Log(ex);
throw ex;
}
// Good!
catch(Exception)
{
Log(ex);
throw;
}
Another alternative is to create a new Exception and pass the current exception as inner exception. The stack trace is shown correctly (complete)
Example:
// Bad!
catch(Exception ex)
{
Log(ex);
throw ex;
}
// Good!
catch(Exception)
{
Log(ex);
Throw new NotImplementedException(“some extra information”, ex);
}
// Bad!
Example: (ToLower() creates a temp string)
int id = -1;
string name = "lance hunt";
for(int i=0; i < customerList.Count; i++)
{
if(customerList[i].Name.ToLower() == name)
{
id = customerList[i].ID;
}
}
// Good! (but not for all cultures)
int id = -1;
string name = "lance hunt";
for(int i=0; i < customerList.Count; i++)
{
// The “ignoreCase = true” argument performs a
// case-insensitive compare without new allocation.
if(String.Compare(customerList[i].Name, name, true)== 0)
{
id = customerList[i].ID;
}
}
// Good! (now also for all cultures)
int id = -1;
string name = "lance hunt";
for (int i = 0; i < customerList.Count; i++)
{
// The StringComparison.OrdinalIgnoreCase argument performs a
// case-insensitive compare without new allocation and for several cultures.
if (String.Compare(customerList[i].Name, name, StringComparison.OrdinalIgnoreCase) == 0)
{
id = customerList[i].ID;
}
}
Een leuke referentie is de zogenaamde Turkey Test.