Wednesday, April 18, 2012

Instagram - Value of Innovation

Many of you may have read or heard about Face book buying out Instagram for $1bn. Interesting deal!


I was reading some blogs on this and thought of consolidating and sharing some of the interesting insights to this deal.



What is Instagram:-


Simply put it is a mobile application which allows users to do some tricks on their photographs and share on Facebook, Twitter, etc. Another interesting fact is that it is an organization of only 12 developers.



Some basic financials:-


Facebook IPO is valued at $ 80bn. With a user base of 800mn, that means $100 per user.


Instagram has a user base of 33mn. So with a buyout of $1bn, it means that it is valued at $30 per user.



Questions:-


So why is Facebook paying $1bn for Instagram? Can’t Facebook develop the Instagram Application? Each of the 12 developers of Instagram would get approx $100mn; would they really be interested in working after that much money?



Answers:-


In all likelihood the 33mn users of Instagram are already part of Facebook. And Facebook definitely has the resources & power to build an application like or even much better than Instagram. But successful consumer product takes more than great technology.


The first product on the market has a big advantage; People get used to the product, invite friends and the growth cycle starts exponentially. And once the user community starts to grow exponentially they are not likely to switch to another product...even if it is better.


Technology can be replicated but not the timing and luck.


Mobile is the future and photos are core to Facebook. And Instagram is better than Facebook in both. And hence the deal is worth the price to Facebook.. though mathematically or numerically it may not make all that sense.


In a similar way, Google video did everything like hosting/sharing a video, but it could not really replicate YouTube. And eventually it had to buy YouTube for $1.6bn though technically it had everything in its Goggle Video.

Monday, July 4, 2011

CSS Sprites and the ASP.NET Sprite and Image Optimization Library

The following link points to an article of Scott Mitchell on using inline Images and CSS sprites to improve the download time of page.

http://dotnetslackers.com/articles/PrintArticle.aspx?ArticleId=612

The number of HTTP requests a browser makes to download a page can be reduced by usingf either of the two techniques: Inline images and CSS. But the primary challenge in using these techniques lies in creating the sprites and CSS rules.
The ASP.NET Sprite and Image Optimization library is a free, open-source library from Microsoft that simplies working with inline images and CSS sprites by automatically creating the sprites and CSS rules. This above article showed how to get started with the Sprite and Image Optimization library in WebForms and MVC applications.

Tuesday, June 7, 2011

Ways to define a JavaScript class

Following article gives a good overview of ways to define JavaScript class.

Though the author seems to have dthe point of effectiveness of using prototypes compared to other methods, the reponses by quite a few folks in the article drive home that point quite convincingly.
http://www.phpied.com/3-ways-to-define-a-javascript-class/

Overriding/Wrapping/Extending ActiveX and XMLHttpRequest object

Sometimes a special or a custom behaviour may be desired whenever an Ajax call is made from the Javascript code in the page.

In Internet Explorer 6 and earlier, XMLHTTP was implemented as an ActiveX object provided by Microsoft XML (MSXML). Beginning with Internet Explorer 7, XMLHTTP is also exposed as a native scripting object.

The native implementation of the XMLHTTP object is designed with cross-browser compatibility in mind. With just a bit of script, it is easy to build a function that works with either version of Internet Explorer, or any browser that supports XMLHTTP
Also it is more efficient to create a native scriptable object than to create an ActiveX object.

var xmlHttp = null;
if (window.XMLHttpRequest) {
// If IE7, Mozilla, Safari, and so on: Use native object.
xmlHttp = new XMLHttpRequest();
}
else
{
if (window.ActiveXObject) {
// ...otherwise, use the ActiveX control for IE5.x and IE6.
xmlHttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');
//Msxml2.XMLHTTP.6.0 ; Msxml2.XMLHTTP.3.0 ; Microsoft.XMLHTTP
}

Overriding ActiveX object: Following link gives the details of overriding Activex object:-
http://stackoverflow.mobi/question797960_Extending-an-ActiveXObject-in-javascript.aspx


The code first stores the instance of the actual ActiveXObject in a variable ActualActiveXObject.
Then the actual ActiveXObject's constructor is overridden with a custom constructor.
The custom constructor creates an instance of the Actual (or the overriden) Activex object.


If the arguement passed to constructor is not "msxml2.xmlhttp", then the instance of the actual Activex object is returned; Else, the rest of the code in the custom constructor is executed which creates a custom object O with certain variables and functions like Open(), Send, ReadyStateChanged(), etc. These custom functions contain user code and eventually call the respective function of the actual instance of the ActiveXObject.



Overriding XMLHttpRequest object: It is on almost similar lines to above code.
The following link and comments in it give details on overriding XMLHttpRequest object.
http://stackoverflow.com/questions/3596583/javascript-detect-an-ajax-event
http://blog.monstuff.com/archives/000252.html

MVC, MVP and MVVM

MVC, MVP and MVVM are patterns, or more specifically architectural patterns, which specify guidelines (or recommended practises) for defining layers within an application and their communication styles for effectively maintaining, scaling, testing, etc the application and its layers.

MVC - Defines 3 layers i.e. Model, View and Controller. Controller receives the UI events and accordingly guides the model and/or view to update themself. And in case the Model is updated from other sources too, it can notify the View(s) to refresh themselves via the observer pattern.
For more details, please refer the following MSDN link:-
http://msdn.microsoft.com/en-us/library/ff649643.aspx

MVP:- is a variant of MVC, with the primary difference that there is no interaction between View and Model. And the Presenter interacts with the View via an interface.
For more details, please refer to following article by Dino Esposito:-
http://msdn.microsoft.com/en-us/magazine/ff955232.aspx

MVVM: Model ,View and View Model is very similar to MVP pattern. Or it is some sort of specialized form of MVP pattern. Here Presentator is known as ViewModel.
Model communicates with ViewModel with notification and ViewModel communicates with View with data binding and command .
Following article gives idea of MVVM at high level:-
http://www.codeguru.com/cpp/cpp/cpp_managed/general/article.php/c18913


Also the following link, too gives decent links to various details about MVC and MVP (some video links too are referrred):-
http://social.msdn.microsoft.com/Forums/en-US/modelingandtools/thread/eecc7b01-cee0-4c20-9086-b1c4cafa6709

Saturday, February 12, 2011

Basic Instincts: Virtual Method; New; Override

Ever wondered how defining a function as virtual impacts its working at run time and how is it intervowen with the access modifiers NEW and OVERRIDE.

The following sample chapter from Vijay Mukhi will make things very clear. The chapter is in form of explanations of snippets of code, but it is very effective

http://www.vijaymukhi.com/documents/books/csbasics/chap9.htm

Essentially to summarize the chapter: Defining a function as virtual gives the power of deciding at run- time which method will be called based upon the assigned object i.e if you have a base class A which is inherited by class B and class C as shown below

Class A
{
public virtual One()
{......
......
}

public Two()
{......
......
}

public virtual Three()
{......
......
}
}


Let's assume that class B inheriting from Class A overrides methods One and Three. Now if an object of class B is assigned to a variable of type A; then on calling a.One() and a.Three(); the implementation of these methods in class B will be called.
Since Two() is not virtual, there is no question of overriding it in B and hence a.Two() will always results in calling the implementation of the method within class A.

Also if a virtual method is not overriden in inherited class; by default the access modifier NEW is assumed thus breaking the chain of the virtual method in inherited classes from thereonwards.

But even if the chain is broken, down the line a new chain can be established if any of the inheriting class down the line, defines the same method as virtual and other classes under it override the implementation of the method. But as specified this would be a new chain.

Sunday, February 6, 2011

Dependency Properties

Somewhat bewildered on my first encounter with this property, I started on a small journey to discover it and hence putting down my findings below for future reference as well as if it helps anyone.

Dependency Property Overview
Primarily to support the functionalities in WPF and Silverlight, designers at Microsoft invented something called as Dependency properties.

In regular .NET code, when you create a property, you typically back it by a private field in the containing class and by defining its getter and setter.
Dependency property is used very much like a normal property but differs significantly in the way it is implemented to support its additional features like
a. Setting via data binding, style, theme;
b. Change Notification;
c. ValidateValueCallBack: Callback to accept or reject new values and returns a Boolean
d. CoerceValueCallback: Can change new values into something more acceptable
The value of the property is determined using certain well-defined values precedence rules.(explained below)
Basic principle of the dependency property - it's an object oriented property i.e. and hence you need to define it within a class. But it can't be any class. It needs to inherit the methods needed to work with a dependency property and this means it has to inherit from DependencyObject or one of its descendants.
(C# only supports single inheritance, so it is important that you choose the correct class to inherit from if you also want properties and methods of a particular control.)
public class MyClass:DependencyObject
{
public static readonly DependencyProperty MyDPProperty =
DependencyProperty.Register("MyDP",typeof(double), typeof(MyClass));
}
And we can't just create an instance of DependencyProperty. The framework needs to know about it to allow it to take part in the common behaviors and hence the solution employed by its designers is to use a static method of Dependency property to create an instance and register it:
public static readonly DependencyProperty MyDPProperty =
DependencyProperty.Register("MyDP",typeof(double),typeof(MyClass));

The DependencyProperty object above is set up to store a value of type double, with name MyDP and to act as a property belonging to MyClass.

This is how all dependency properties are created and they have to be public static readonly fields. The reason is that the property belongs to the class and it’s the implementation that sorts out the instance being used. That is there is only one property object shared among all of the instances of the class that uses it.

There are a number of overloaded Register methods but at the very least you have to specify:-
• the name of the property as a string "MyDP" in the example
• the type of the property typeof(double) in the example
• the type of the class the property belongs to typeof(MyClass) in the example.

Two ways of referring to the property either by its name i.e. MyDP or by the variable MyDPProperty. You can also register a range of metadata values and callbacks but this is the minimum you need to create a custom dependency property.

Value precedence
Dependency properties obtain their value from a variety of inputs. What follows is the order the Silverlight property system uses when assigning the runtime values of dependency properties, with the highest precedence listed first:
a. Animations: If an animation is currently running, and that animation is changing the property value, Silverlight uses the animated value.
b. Local value: If you've explicitly set a value in XAML or in code, Silverlight uses the local value. If you set a property using a resource or data binding, it's considered to be a locally set value.
c. Styles: Silverlight styles allow you to configure multiple controls with one rule. If you've set a style that applies to this control, it comes into play now.
d. Property value inheritance: Silverlight uses property value inheritance with a small set of control properties, including Foreground, FontFamily, FontSize, FontStretch, FontStyle, and FontWeight. That means if you set these properties in a higher level container (like a Button or a ContentControl), they cascade down to the contained content elements (like the TextBlock that actually holds the text inside).
e. Default value: If no other property setter is at work, the dependency property gets its default value. The default value is set with the PropertyMetadata object when the dependency property is first created.

One of the advantages of this system is that it's very economical. For example, if the value of a property has not been set locally, Silverlight will retrieve its value from the template or a style. In this case, no additional memory is required to store the value. Another advantage is that different property providers may override one another, but they don't overwrite each other. For example, if you set a local value and then trigger an animation, the animation temporarily takes control.

References
Couple of resources where you can get decent information on the subject:
1. Pro WPF in Vb 2010: Chapter 4 Dependency Properties
2. http://www.i-programmer.info/programming/wpf-workings/443-inside-dependency-properties-.html - A useful link explaining the subject in a very easy manner (and much of what I have stated below is from this link)