Monday, November 24, 2008

Google Advice for writing testable code

From Miško Hevery's blog:

Warning Signs

  • new keyword in a constructor or at field declaration
  • Static method calls in a constructor or at field declaration
  • Anything more than field assignment in constructors
  • Object not fully initialized after the constructor finishes (watch out forinitialize methods)
  • Control flow (conditional or looping logic) in a constructor
  • Code does complex object graph construction inside a constructor rather than using a factory or builder
  • Adding or using an initialization block

Flaw #2: Digging into Collaborators

Warning Signs

  • Objects are passed in but never used directly (only used to get access to other objects)
  • Law of Demeter violation: method call chain walks an object graph with more than one dot (.)
  • Suspicious names: contextenvironmentprincipalcontainer, or manager

Flaw #3: Brittle Global State & Singletons

Warning Signs

  • Adding or using singletons
  • Adding or using static fields or static methods
  • Adding or using static initialization blocks
  • Adding or using registries
  • Adding or using service locators

Flaw #4: Class Does Too Much

Warning Signs

  • Summing up what the class does includes the word “and”
  • Class would be challenging for new team members to read and quickly “get it”
  • Class has fields that are only used in some methods
  • Class has static methods that only operate on parameters"

LINQ Reference Documentation

From Charlie Calvert's Community Blog:

"The LINQ documentation created by Microsoft is available both inside Visual Studio, and for free via the MSDN library found on the WEB. Here are some important pages from that documentation that can help you navigate through the online reference material that Microsoft has prepared for LINQ developers:

· The Root MSDN Library Page: http://msdn.microsoft.com/en-us/library/default.aspx

· .NET Development: http://msdn.microsoft.com/en-us/library/aa139615.aspx

· .NET Framework 3.5: http://msdn.microsoft.com/en-us/library/w0x726c2.aspx

· System.Linq: http://msdn.microsoft.com/en-us/library/system.linq.aspx

· System.Data.Linq: http://msdn.microsoft.com/en-us/library/system.data.linq.aspx

· System.Xml.Linq: http://msdn.microsoft.com/en-us/library/system.xml.linq.aspx

· Code Generation: http://msdn.microsoft.com/en-us/library/bb399400.aspx

· More on Joins: http://msdn.microsoft.com/en-us/library/bb311040.aspx

· For more information on the operators, see the section of the online help called “The .NET Standard Query Operators.” It is written by Anders Hejlsberg and Mads Torgersen. The URL is http://msdn.microsoft.com/en-us/library/bb394939.aspx

I would not suggest using these references materials as a primary means of learning LINQ. However, if you have a book or other guide to LINQ development, then this reference material can be a useful addendum to that text. If you understand in a general way how LINQ works, but need answers to detailed questions, the links provided here may sometimes help you find answers."

Saturday, November 22, 2008

Money-Saving Meal Plans at Whole Foods

Advice for constructing a menu for the week, from Whole Foods. Kind of a cool idea!

Wednesday, November 19, 2008

How To: Use Impersonation and Delegation in ASP.NET 2.0

Has an API to login as a different user. See also this link: How To: Encrypt Configuration Sections in ASP.NET 2.0 Using RSA

And this link: Encrypting configuration files using protected configuration, to avoid the dreaded "The RSA key container could not be opened" error. It tells you to encrypt using this command:
aspnet_regiis -pa "NetFrameworkConfigurationKey" "ASPNET"

So, for example, to encrypt user identity (in one line):
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -pa "NetFrameworkConfigurationKey" "ASPNET" -pef system.web/identity C:\Inetpub\wwwroot\SimpleEmailWebService


The relevant code is this:
    // From http://msdn.microsoft.com/en-us/library/ms998351.aspx

public class NativeWindowsSecurity
{
// Declare signatures for Win32 LogonUser and CloseHandle APIs
[DllImport("advapi32.dll", SetLastError = true)]
public static extern bool LogonUser(
string principal,
string authority,
string password,
LogonSessionType logonType,
LogonProvider logonProvider,
out IntPtr token);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool CloseHandle(IntPtr handle);

public enum LogonSessionType : uint
{
Interactive = 2,
Network,
Batch,
Service,
NetworkCleartext = 8,
NewCredentials
}

public enum LogonProvider : uint
{
Default = 0, // default for platform (use this!)
WinNT35, // sends smoke signals to authority
WinNT40, // uses NTLM
WinNT50 // negotiates Kerb or NTLM
}
}

Saturday, November 15, 2008

CSU Library Research Databases

  • EBSCOhost Research Databases: Menu of databases provided through EBSCO Publishing.
  • Business Source Complete (1886- some full text): Index, abstracts, and full text covering scholarly business journals on management, economics, finance, accounting, international business and much more.
  • Wall Street Journal (1984-): Contains full text articles from the Wall Street Journal from January 2, 1984 through today's issue. Browse issues, or search for terms in citation, abstract, or article text.
    • Use keyword search on:
      • your company
      • supply chain
      • logistics
      • quality
      • strategy
      • etc