Tuesday 9 November 2010

Windows Live Writer 2011

Yes, I am using the new windows live writer 2011. I don’t particularly like the year part in this software, don’t know why..2011 sounds like a strange figure to me, Strange for Microsoft software!. Visual Studio 2010, Office 2010, SharePoint 2010…………………you know what i mean ??, Anyhow, I like this version of the live writer and it has a bunch of improvements around UI and bits of bobs of functionality. Until later version, I’ll definitely be using Live Writer!

Friday 5 November 2010

Enter the Cloud!

I’m migrating some of my test web applications a.k.a simple concept web apps to the windows cloud, a.k.a ‘The Windows Azure Platform’. I'm all excited to share my experiences with Windows Azure, SQL Azure and App Fabric.

I encourage you to download the Training Kit from Microsoft and give it a go.

The tools you might need to get started are

Either

1] Windows Azure Tools for Visual Studio

or  Install Visual Web Developer 2010 Express.

or if you have another development language (Java,PHP,Ruby), try

2] This

JS Trick

Ever wondered how to close that damn browser window without getting a warning from the browser ?.

Well, I've gone through that many a times before when trying to close a window(subject)  from either the main window or any other window which did not create the subject.

and…and i remember the solution, which i had devised for IE. (not sure about other browsers and I'll leave that for you ).

You have to remember, the window.open method creates a reference to the window.opener ??    (Hint, Hint! )

function CloseWindow(){

//removes the previous window.opener reference and

//tricks the browser not to display the annoying warning message.

window.opener = ‘fake’;

window.close();

}

Winking smile

Thursday 23 September 2010

Tip of the day – A good use of auto implemented properties.

A very practical use of auto implemented properties could be to create a immutable lightweight class. An auto implemented property is a ‘property’ in C# without fields. The C# JIT Compiler generates the IL with a field for the auto implemented properties. (hence the name). The IL also replaces the Get and Set accessor stubs in the Properties to return and set the automatically generated field.

Take a look at the below code ( class ‘Books’). There are Title, Author and PublshedYear auto implemented properties. Notice the set is private, This makes the ‘Books’ class immutable.

autoprop

The tip is to use this kind of construct to replace structs when ever a reference type is required. Also notice that the constructor is made ‘private’. Simply because i find the factory method ‘CreateBook’  semantically appealing to call the private constructor rather than having to use the auto implemented property directly in the constructor for initializing the Books object.

Take a look at the IL for Books.,  Notice the ‘k__BackingField’ feild generated by the C# Compiler.

image

//////////////get_Author: string() IL////////////////////

.method public hidebysig specialname instance string
        get_Author() cil managed
{
  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
  // Code size       11 (0xb)
  .maxstack  1
  .locals init (string V_0)
  IL_0000:  ldarg.0
  IL_0001:  ldfld      string ConsoleApplication1.Books::'<Author>k__BackingField'
  IL_0006:  stloc.0
  IL_0007:  br.s       IL_0009
  IL_0009:  ldloc.0
  IL_000a:  ret
} // end of method Books::get_Author

 

//////////////////set_Author:void(string) IL////////////////

.method private hidebysig specialname instance void
        set_Author(string 'value') cil managed
{
  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
  // Code size       8 (0x8)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  ldarg.1
  IL_0002:  stfld      string ConsoleApplication1.Books::'<Author>k__BackingField'
  IL_0007:  ret
} // end of method Books::set_Author

Now, a demo of using the above immutable lightweight class

democode

Happy patterns discovery..

I’ve used the MSDN example here to illustrate.

Sunday 19 September 2010

Design Patterns – Types

Design patterns are proven practises and principles for building enterprise software. They generalize solutions to common problems.  By adapting design patterns in our software architecture, we leverage the proven solutions and concepts. This makes the code easier to maintain / understand / relate to.

Design patterns are broadly classified into the following categories.

1] Structural Patterns

- Focus on building flexibility,maintainability and security

2] Creational Patterns

- Focus on increasing flexibility,i.e what , who, how and when of object creation.

3] Behavioural Patterns

- Focus on algorithms and communication between them.

I’ll start with the Structural Patterns in my next post.