The Never Ending Ooze

Saturday, October 25, 2014

Visual Studio 2014 CTP

Playing with Visual Studio 2014 CTP and building a demo app using ASP.NET VNext and Entity Framework 7. An article on a demo project coming over soon. You can download a copy from the following location:

Monday, October 20, 2014


This is just a collection of things I want to keep at one place, so that I can refer back later without going to multiple websites or blogs:

What is the advantage of using var self = this in knockout view models?

Partial methods enable the implementer of one part of a class to define a method, similar to an event. The implementer of the other part of the class can decide whether to implement the method or not. If the method is not implemented, then the compiler removes the method signature and all calls to the method. The calls to the method, including any results that would occur from evaluation of arguments in the calls, have no effect at run time. Therefore, any code in the partial class can freely use a partial method, even if the implementation is not supplied. No compile-time or run-time errors will result if the method is called but not implemented.


There are several rules to follow when you are working with partial class definitions:
  • All partial-type definitions meant to be parts of the same type must be modified with partial. For example, the following class declarations generate an error:
    public partial class A { }
    //public class A { }  // Error, must also be marked partial
  • The partial modifier can only appear immediately before the keywords classstruct, or interface.
  • Nested partial types are allowed in partial-type definitions as illustrated in the following example:
    partial class ClassWithNestedClass
        partial class NestedClass { }
    partial class ClassWithNestedClass
        partial class NestedClass { }
  • All partial-type definitions meant to be parts of the same type must be defined in the same assembly and the same module (.exe or .dll file). Partial definitions cannot span multiple modules.
  • The class name and generic-type parameters must match on all partial-type definitions. Generic types can be partial. Each partial declaration must use the same parameter names in the same order.
  • The following keywords on a partial-type definition are optional, but if present on one partial-type definition, cannot conflict with the keywords specified on another partial definition for the same type:
Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type. For client code written in C# and Visual Basic, there is no apparent difference between calling an extension method and the methods that are actually defined in a type.

The most common extension methods are the LINQ standard query operators that add query functionality to the existing System.Collections.IEnumerable andSystem.Collections.Generic.IEnumerable<T> types. To use the standard query operators, first bring them into scope with a using System.Linq directive. Then any type that implements IEnumerable<T> appears to have instance methods such as GroupByOrderByAverage, and so on. You can see these additional methods in IntelliSense statement completion when you type "dot" after an instance of an IEnumerable<T> type such as List<T> or Array

If you do implement extension methods for a given type, remember the followingpoints:
  • An extension method will never be called if it has the same signature as a method defined in the type.
  • Extension methods are brought into scope at the namespace level. For example, if you have multiple static classes that contain extension methods in a single namespace named Extensions, they will all be brought into scope by the using Extensions; directive.
Lambda Expressions (C#)
A lambda expression is an anonymous function that you can use to create delegates or expression tree types. By using lambda expressions, you can write local functions that can be passed as arguments or returned as the value of function calls. Lambda expressions are particularly helpful for writing LINQ query expressions.
To create a lambda expression, you specify input parameters (if any) on the left side of the lambda operator =>, and you put the expression or statement block on the other side. For example, the lambda expression x => x * x specifies a parameter that’s named x and returns the value of x squared. 

The following rules outline the usage guidelines for the Finalize method:
  • Implement Finalize only on objects that require finalization. There are performance costs associated with Finalize methods.
  • If you require a Finalize method, consider implementing IDisposable to allow users of your class to avoid the cost of invoking the Finalize method.
  • Do not make the Finalize method more visible. It should be protected, not public.
  • An object's Finalize method should free any external resources that the object owns. Moreover, a Finalize method should release only resources that the object has held onto. The Finalize method should not reference any other objects.
  • Do not directly call a Finalize method on an object other than the object's base class. This is not a valid operation in the C# programming language.
  • Call the base class's Finalize method from an object's Finalize method.
    The base class's Finalize method is called automatically with the C# and C++ destructor syntax.


The following rules outline the usage guidelines for the Dispose method:
  • Implement the dispose design pattern on a type that encapsulates resources that explicitly need to be freed. Users can free external resources by calling the public Dispose method.
  • Implement the dispose design pattern on a base type that commonly has derived types that hold onto resources, even if the base type does not. If the base type has a Close method, often this indicates the need to implement Dispose. In such cases, do not implement a Finalize method on the base type.Finalize should be implemented in any derived types that introduce resources that require cleanup.
  • Free any disposable resources a type owns in its Dispose method.
  • After Dispose has been called on an instance, prevent the Finalize method from running by calling the GC.SuppressFinalize. The exception to this rule is the rare situation in which work must be done in Finalize that is not covered by Dispose.
  • Call the base class's Dispose method if it implements IDisposable.
  • Do not assume that Dispose will be called. Unmanaged resources owned by a type should also be released in a Finalize method in the event thatDispose is not called.
  • Throw an ObjectDisposedException from instance methods on this type (other than Dispose) when resources are already disposed. This rule does not apply to the Dispose method because it should be callable multiple times without throwing an exception.
  • Propagate the calls to Dispose through the hierarchy of base types. The Dispose method should free all resources held by this object and any object owned by this object. For example, you can create an object such as a TextReader that holds onto a Stream and an Encoding, both of which are created by the TextReader without the user's knowledge. Furthermore, both the Stream and the Encoding can acquire external resources. When you call theDispose method on the TextReader, it should in turn call Dispose on the Stream and the Encoding, causing them to release their external resources.
  • Consider not allowing an object to be usable after its Dispose method has been called. Re-creating an object that has already been disposed is a difficult pattern to implement.
  • Allow a Dispose method to be called more than once without throwing an exception. The method should do nothing after the first call.

I learnt today that it is not good practice to access Session in ASP.NET Web API. The reason for this is that REST is stateless by design. By adding session, that stateless nature of REST is being lost. The whole idea of RESTful service is that every resource is uniquely addressable using a universal syntax for use in hypermedia links and each HTTP request should carry enough information by itself for its recipient to process it to be in complete harmony with the stateless nature of HTTP.

But if someone really needs to, then they need to implement the IRequiresSessionState interface in a custom HTTP handler and they would be able to have read/write access over the Session values. Here is a link which talks about how to do this in code:

Service Oriented Architecture

SOA is the decomposition of a system into autonomous or nearly autonomous units of responsibility and exposure.

  • Decomposition can take various forms - functional, volatility based
  • Either case, services "orchestrate/manage" and "expose" functionality
SO-Applications are based on loosely coupled services.

A SO-application is essentially an API exposing functionality to the outside world through a set of standards and protocols.
Regardless of the complexity of the service, it needs to:
    • Be fault handled
    • Leave system in a consistent state - transactional
    • Be secure
    • Handle threading securely
Will complete this blog later.

Saturday, October 11, 2014

Understanding the IIS 7.0 Integrated pipeline mode

Here is how the Classic mode in IIS6 used to work: 

This image is from this location.

In the new Integrated mode present in IIS7 onwards, a request from the browser to the server comes to http.sys which works with Windows Activation Service and W3SVC to handle this request. WAS and W3SVC get their configuration related data from applicationHost.config file. WAS and W3SVC are both part of svchost.exe file. 

The request then reaches the integrated pipeline, which fires certain events like MapRequestHandler, LogRequest, PostLogRequest, BeginRequest, AuthenticateRequest etc, which are necessary to handle this request. Native and custom modules subscribe to these events. The order in which you register modules can have a big effect on request processing. The managed module native engine then handles ASP.NET integration by loading application domain. App domain then initiates the HTTPContext and HTTPApplication classes. So, this module is the most important module. 

Finally the request is ready to be served and goes back to the browser through http.sys.

Here is an image from

So, one of the advantages of Integrated mode over Classic mode is that performance is better since now requests are tightly integrated with IIS and IIS does not have to load a separate ISAPI extension to handle any requests coming its way

Sunday, October 05, 2014

Why CSS is difficult and why it needed improvements like SASS

Why CSS needs some add-ons:

  • Does not allow for named colors, so we have to mention colors throughout the web page and if the UI changes at any time in the future, then all these instances need to be manually replaced.
  • We cannot reuse sections of the CSS which can be used at other places within the website-sort of like SASS mixins.
  • CSS does not allow for calculations to be used 
Now, some information about SASS:
  • SASS has 2 syntaxes - SASS and SCSS. SASS was based on indention and was the original syntax. SCSS looks and feels like CSS.
  • Allows for creating variables which can be assigned the name colors and then those variables could be used throughout your file to assign colors. This ensures that whenever the design of the website or web app needs to change in the future, then it could be done by changing the value of the variable at one place and the changes will reflect throughout the application.
  • Allows for calculations like width: 10px * 2;  or even color: #FFFF / 10;
  • Allows for string interpolation like:
    • $root: "/SOME_PATH/'
    • Now $root can be used to insert its value wherever it is needed, for instance, in forming a URL. Since the root variable is declared at a central location, if this path changes anytime in the future, we just need to change it in one place. You just need to use it like this #{$root 
  • Allows for indentation in the file, so as to improve readability.
  • Allows for certain specified directives, which tell the processor to do certain things. The directives that are common are:
    • @import
    • @extend
    • @mixin
    • @function
    • Control directives like:
      • @if / @else if
      • @for
      • @each
      • @while

Responsive Web Design

Just capturing some notes on how to enable responsive web design in your web app.
Javascript will come to your rescue in enabling RWD. Media queries come into the picture here.

  • Polyfills for media queries-respond.js and css-mediaqueries.js
  • Pocketgrid can be used for enabling RWD-the advantage is percentage based page layout. PocketGrid has many nice features:
    • PocketGrid is really lightweight, so you can use it in all your projects at no cost (Twitter Bootstrap is about 200x bigger, even minified!)
    • Twitter Bootstrap 2's grid has only 1 breakpoint (like many grid systems), whereas with PocketGrid you can define as many breakpoints as you want!
    • Twitter Bootstrap breakpoints are hard-coded and limited, whereas PocketGrid breakpoints are free and unlimited!
    • Twitter Bootstrap has only 12 columns, whereas PocketGrid columns are unlimited!
    • PocketGrid is one of the very few semantic grids (especially pure CSS grids!): you don't have "span4" or "small-6 large-2 columns" classes everywhere in your HTML: column size should be defined in the stylesheet, not in the HTML! That's the PocketGrid philosophy!
    • Percentage sizing is more natural and more precise than using a number of columns
    • (how can you make 5 columns in a 12 or 16-columns system? It's impossible! With PocketGrid, just put "width:20%" on your blocks, easy!)
    • PocketGrid does not require a CSS preprocessor such as LESS or SASS (but you can use one if you want).

Improve performance of web front ends

There are different ways in which you can improve the performance of your web fronts:

1. CSS placement: One should place the css links in the Head of the HTML page. The reason for this is that the browser renders the HTML elements based on the default style of the browser. However, after rendering if it encounters any css links, it re-renders the HTML elements using the new styles. To avoid this churn, it is better to have the browser see the css links first thing as it walks down the HTML page. The best place to do this is to place the CSS links in the <head> at the top of the HTML page.

2. Script placement: Script links work exact opposite to the CSS links. Whenever the browser sees a script link, it pauses all rendering and parses through the script links. This delays the rendering of the page. To avoid this, the script links should be placed at the bottom of the <body> tag. This ensures that the browser sees the script links as the last thing when rendering an HTML page.

3. Content Delivery Networks (CDN): Some 3rd parties allow hosting your script, jquery and css files. There are various advantages of this:

  • Pre-Caching: If a website has encountered a particular file needed for your web app, prior to visiting your web app, then the browser would have cached version of that particular file and would pick it up from your browser cache instead of downloading it all over again. This saves internet bandwidth and makes loading of web pages faster.
  • Distributed servers across the world: Most of the CDNs have distributed servers across the world. This ensures that the resource files are picked up from the nearest server of the CDN. This can cause significant improvement in page load times.
  • High capacity infrastructure: The CDNs have very high capacity servers and this also helps in loading web pages faster.
  • Reduced load and bandwidth: Hosting your non-custom files/3rd party files on CDN networks ensures that the load on your website servers will be lesser.
4. Minification: Reducing the size of the javascript files will make your site more performant and scalable and save on bandwidth. It also helps in making your code not as readable, which prevents in losing any intellectual property which might be in the javascript files. Minification is also known as Uglification. Grunt can help in minifying your javascript files. Grunt contrib uglify is the command which will minify your code for you.

5. Concatenation: When the browser is rendering an HTML page, it sends a request back to the server each time it encounters a resource file e.g. css file or script file. So, if your code has 4 script files, then it means that 4 round trips are happening to the server from the browser. So, it is better to have 1 script file with all the code that you have in those 4 script files. For reading purpose, it is better to have script segregated in separate files, but from the deployment perspective it is better to have all that code concatenated in a single file. So, before deploying your code to the production server, please concatenate all your code in a single file. Grunt will be able to do this for you. Remember-Grunt is your Javascript task runner. It will do all of these tasks for you.

Friday, September 13, 2013

Learning ASP.NET WebAPI

Wednesday, September 20, 2006

Model Driven Architecture..Huh! What is that?

As you all would have noticed, lately I have been pondering a lot about architecture, design and the way software development can be made easier for the software community. Well, this led to me Model Driven Architecture. Now, you would wonder-what is different about Model Driven Architecture? After all, all software starts with design where you develop a sort of model of the end software.

First let me try to explain a problem which we software developers face almost everyday-CHANGING TECHNOLOGY. First there was VB, then came VB.NET, first there was remoting, then came web services. Each time a new technology comes into the market, lot of rework needs to be done. Add to this the plethora of rapidly changing requirements and the ability that your software needs to interact with other systems and you get a fairly complex scenario which haunts you everyday. I on a personal basis hate the client asking me to change the application so that his application can run on Oracle database as well.

Allow me to explain a little more, Model Driven Architecture is a new way of writing just what you thought-“Specifications”. Here, no technology is taken into consideration. So, what do you exactly write? You develop a platform independent base UML model aptly called Platform Independent Models (PIMs). You are not supposed to concentrate on the language to be used or the database on which the software will run or the number of frigging threads the application will spawn. You concentrate only on the functionality and the end behavior of the application. There is no relation what so ever with the implementation details.

So, what is the benefit of this sort of architecture?

With today’s fast changing technology environment, lots of new platforms and infrastructure are coming into the market. Now what happens to your existing applications? If your applications have been written solely targeted towards a particular platform or infrastructure, then they become redundant-right? So, that means you lose all your investment that you have been putting into technology hoping for a better tomorrow. Now, that’s a really scary situation. This is where Model Driven Architecture steps into the picture.

MDA is already being projected as the next big step to be taken by the software industry. At the heart of the MDA development is UML, which involves developing models in order to develop your application. So, during the analysis of the requirements, UML is used to develop a model in a standard way which acts like a blueprint for your application. But you would be wondering how can just developing a model, lead to the development of the entire application. So, here in order for the application to be targeted towards a particular platform or infrastructure, the Platform Independent Model needs to be converted into a Platform Specific Model (PSM). So, if you wish to put it into simple words, a PIM sits at the center of the application and then a PSM is written around the PIM. The PSM can be written in any technical language-be it CORBA, or .NET or JAVA. The business functionality and the behavior of an application are etched into the PIM and the UI and the UI components are written in any available language.

It is then the responsibility of the platform specialists to convert the model into one targeted towards a specific platform like CCM, EJB or MTS. Standardized tools are used in order to do this conversion from PIM to PSM. This is one area where a lot of scope is still there for research and development due to the fact that although the tools being used today use standard mappings to do the conversion, there is still a lot of human intervention involved. So, this is a sort of developing art which needs some hand-holding even today.

The next step is the actual generation of the code. Finally, the software developers would have heaved a sigh of relief here-after all what will they do if everything is done by the model. The actual code generation will involve generating a lot of configuration files, interface files and so on. If the models generated using UML are complete or encompass the entire functionality of the application, there will be lesser work to do during the PSM conversion phase and the better the application nitty-gritty’s and runtime behavior have been handled in the PSM, the lesser code will have to generated.

This type of architecture is still in its infancy stage right now and if you expect that you can generate all your code using models TODAY, then you are probably mistaken. MDA offers just another layer of reusability below the development tools which we all are already using these days. This art of architecture still has to grow a lot before we start searching for expert UML modelers rather than expert C# developers.

Wednesday, September 06, 2006

Domain Driven Design

Well, a couple of google searches later, I have come to know that there is infact a community of developers who are working on providing domain specific designs and they have coined a name to it-Domain Driven Design (DDD)-COOL!

DDD works on the assumption that all software that is developed is BASED on a proper understanding of the domain-its intricacies, its complexities. So, rather than spending hours trying to solve the technical complexities, a developer should be spending more time with the analyst or domain expert trying to understand the complexities involved in the domain on which the software or code piece is to be written. DEVELOPERS AND ANALYSTS WORKING TOGETHER??? Since when did this become possible? After all, they are supposed to be entirely different backgrounds. A developer might be someone who has done his B.S/B.Tech., whereas the analyst might be some arts graduate who has done his MBA from some B School and has some expertise on the domain say finance. How can these two different types of creatures survive together?

But howsoever impossible it might sound, the domain and technology experts need to sit together and pool in their knowledge of the domain so that it can form the basis of the software. Together, their knowledge can be invaluable (obviously only when the mostly egoistical programmer learns to share his/her knowledge ;-) ) This is not so impossible, since I have to come to know that in a large account of Tavant Technologies the developers are in fact working with the analysts in order to understand the financial domain more-thanks to Nitish for this information.

Design Patterns based on Domains

Recently we have been discussing around domains-which problems we had faced while working on what domain, how we had solved it, which domain offers more job opportunities and stuff like that. This made us come up with the premise that probably there should be design patterns targetted towards specific domains. Since design patterns offer solutions to complex problems which have been faced by developers across technologies across the world, maybe there should be a forum where similar design patterns are discussed for problems faced while developing an application for a particular domain. Dont you think this would offer more lucid designs and help architects and developers to think alike. Rather than focussing on some technical issue, they can rather concentrate on providing a better solution itself to the user. Need to do some research on this.