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.

Saturday 18 September 2010

My love for patterns and discovery of them..

It all started in my undergraduate days back in 2003 when i used to work a lot on VB & C++. I had no idea that patterns existed then!. One fine day a friend of mine suggested using a ‘Singleton’. Since than I've had the hunger for discovering more and more of ‘patterns’ and their usage.

After i moved to the managed world (.Net) it started appealing more and more and today, i cannot think of an application without it. I’ve moved on to application architecture and business processes all the way realizing how vital the role of patterns in real world development (civil engineering  to software engineering). Apart from all the other stuff that still interests me., I’ve decided to take a rather focussed approach to patterns, software design and application architecture from now. I look forward to a sound discussion with you all on them.