Showing posts with label Webapplication. Show all posts
Showing posts with label Webapplication. Show all posts

Saturday, May 7, 2011

Application Performance and Architectural Problems You can Find in One Hour

Application Performance and Architectural Problems You can Find in One Hour: "Too many database statements, slow running queries, chatty or slow remoting calls, hidden exceptions, heavy garbage collection or problematic 3rd party code. These are the most common problems we find in most applications. In this blog I give you a quick overview of the problems you can find within an hour on the example of a distributed Java/.NET Enterprise Application.



Add to digg
Add to StumbleUpon
Add to del.icio.us
Add to Google



"

Saturday, April 3, 2010

12 Free Or Cheap Web Apps Your Startup Needs Now

12 Free Or Cheap Web Apps Your Startup Needs Now: "

startup

Running your startup, don't waste time on tasks that apps can help you do -- especially if those apps are free or cheap.


Thankfully, there's a post on the Flexvite blog that put together a list of 12 cheap or free web tools that help you with that.


12 Free Or Cheap Web Apps Your Startup Needs Now →

For Brainstorming, Use Mindmeister.com

For Brainstorming, Use Mindmeister.com
When you're brainstorming, it's often overlooked that you need to store and organize your ideas using things such as mind maps. Mindmeister.com lets you do that with others and share them.


Source: Flexvite blog


Check If The Domain Names You Want Are Available

Check If The Domain Names You Want Are Available
Nxdom.com searches recently expired domain names for those that start or end with the names you want. More useful than standard whois searches.


Source: Flexvite blog


Ud.com Checks Both Domain Names And Social Networks For Your Name

Ud.com Checks Both Domain Names And Social Networks For Your Name
Also helping you find a name that's unique and useful, Ud.com checks both domain names and social networks to see if your ideas are already taken.


Source: Flexvite blog


To Make Mockups, Balsamiq Is Your App Of Choice

To Make Mockups, Balsamiq Is Your App Of Choice
Balsamiq is a very popular app for making mockups of various apps, and rightfully so. It's fun and easy to use, and saves a lot of time.


Source: Flexvite blog


Vyew.com Is Great For Collaboration And Feedback

Vyew.com Is Great For Collaboration And Feedback
Vyew.com is a free collaboration, conferencing and sharing app, that lets you work together remotely, create screenshots together, and is also a great way to get feedback from your users.


Source: Flexvite blog


Pivotal Tracker Is A Great (And Free!) Project Management App

Pivotal Tracker Is A Great (And Free!) Project Management App
There are plenty of great web-based project management apps out there. Pivotal Tracker is based around prioritizing between tasks with a drag-and-drop interface. And oh, unlike a lot of project management apps, it's free.


Source: Flexvite blog


For Cheap, Quick And Dirty User Feedback, Use UserTesting.com

For Cheap, Quick And Dirty User Feedback, Use UserTesting.com
UserTesting.com pays users to interact with your app, and records how they interact with it as well as their feedback and user summaries. It's very useful and pretty cheap.


Source: Flexvite blog


Litmus Lets You Test Your App Accross A Range Of Browsers

Litmus Lets You Test Your App Accross A Range Of Browsers
Litmus is an app that lets you test the way your app looks in a bunch of browsers, and also lets you test what your emails look like. Unlike a lot of apps that have this functionality, it's 100% browser based.


Source: Flexvite blog


For Email Marketing, Flexvite Recommends MadMini

For Email Marketing, Flexvite Recommends MadMini
Apparently, MadMini is 'simple and beautiful email marketing.' Email is a very powerful channel and is often overlooked in this era of SEO and social media. MadMini helps you build your email list and market to it.


We've also heard a bunch of great things about MailChimp, which we would personally recommend.


Source: Flexvite blog


Google's Cloud Is Free At First

Google's Cloud Is Free At First
Flexvite recommends Google's App Engine, its cloud hosting service, because it's free until your app gets traction. Amazon Web Services seems to be the choice of most startups though.


Source: Flexvite blog


Survey.io Lets You Make Surveys To Get Customer Feedback

Survey.io Lets You Make Surveys To Get Customer Feedback
Customer surveys, either before or after your app is live, are very important. Survey.io lets you make these easily. Another popular alternative is Wufoo.


Source: Flexvite blog


Ask500People.com Lets You Poll Random People About Your App

Ask500People.com Lets You Poll Random People About Your App
We love this one. Asking 500 random people about your app (or logo, or whatever) might sound like a waste of time but we think it should yield interesting results, at least. Ask500People.com does this quickly and easily.


Source: Flexvite blog

Join the conversation about this story »



"

Friday, March 19, 2010

ASP.NET Performance Framework

ASP.NET Performance Framework: "

At the start of the year, I finished a 5 part series on ASP.NET performance - focusing on largely generic ways to improve website performance rather than specific ASP.NET performance tricks. The series focused on a number of topics, including merging and shrinking files, using modules to remove unecessary headers and setting caching headers, enabling cache busting and automatically generating cache busted referneces in css, as well as an introduction to nginx.


Yesterday I managed to put a number of those things together into a framework which I hope will make it easier for developer to leverage these best practices. The project is called Metsys.WebOp, and you can download it from github. It comes with a sample application, which not only shows how to use the framework, but also has all the documentation you'll hopefully need.


The first part of the framework is a console application which is meant to be run as part of your build process. This is driven by a text file which supports 4 commands - merging files together, shrinking them, generating cache busting hashes and pre-zipping files. Here's what the sample app's command file looks like:


#combine JS files
combine: js\all.js: js\jquery.js, js\jquery.rollover.js, js\web.js

#combine css files
combine: css\merged.css: css\reset.css, css\main.css

#shrink the generated files
shrink: js\all.js, css\merged.css

#generate cache-busting resource hashes
busting: hashes.dat

#pre-zip our files
zip: js\all.js, css\merged.css

The next part is meant to be used from within a MVC application (it wouldn't take too much effort for someone to make it work with WebForms) - first by allowing you to configure the runtime component, and then by providing extension methods to HtmlHelper. Essentially this gives you 4 methods, Html.IncludeJs, Html.IncludeCss, Html.Image and Html.ImageOver. You can also toggle debug mode, which'll make all of this transparent during development (nothing worse than dealing with merged and shrank files in development).


The last part are a couple HttpModule which make everthing possible. The Zip module will returned the pre-zipped files (generated by the build process) should the browser accept zip files. The WebOp module will remove unecessary headers and add caching headers to js, css and images - only really practical if you are also using the cache busting featuers.


You can download the project from http://github.com/kseg/Metsys.WebOp.


You might also be interested in checking out the mscd project, which does a lot of the same stuff, but is probably more mature.

"

Friday, March 5, 2010

An innovative architect to develop business web forms more efficiently

An innovative architect to develop business web forms more efficiently: "The article introduces an innovative architect to develop business web forms in enterprise software development which is better performance, higher productivity, more configurability and easier maintainability than traditional either ASP.NET or MVC development.

When we develop a web form in ASP.NET or MVC, we need work on the following items,
1. create view template and code behind (controller)
2. style adjustment
3. write event handlers for all actions
4. control visibility of web controls for different actions manually
5. permission integration manually
6. hard to write unit tests (not for MVC)
7. something else

With all of those staff, the source code of developed web forms are very complex usually by mixed logics of webcontrols' visibility control, business logics, style management, permission check etc. The web forms are less productive, bug-ness and hard maintainable.

RapidWebDev solution implements a new UI framework based on ASP.NET which is designed to solve the facing problems. The principle of design is to abstract requirement of web forms for usual business scenarios and define xml schema to configure web forms so that user behavior, style, permission are all managed by the framework. And some interfaces of the framework are required to be implemented which are callback for user behaviors. E.G. there is a query panel with filters configured. When an user clicks query button in query panel, method Query of the implementation to interface IDynamicPage will be invoked with query parameters.

With this design,
1. web forms are configurable and maintainable.
2. code complexity is decreased obviously.
3. implementations are reusable and testable
4. consolidate ui style by the framework"

Wednesday, March 3, 2010

Download Free Web Application Toolkits

Download Free Web Application Toolkits: "Free Web Application toolkits by Microsoft helps web developers to add rapid functionality like Bing Maps integration or adding social capabilities etc Click here to download and read more about Web Application toolkit.



These Web Application Toolkits are available for the following things:-


Mobile Web Applications


Make your website "Social"


Toolkits for Calendars


Toolkit for "Freemium" Applications


Toolkit for [...]



...


"

Friday, February 19, 2010

Integrating Twitter Into An ASP.NET Website

Integrating Twitter Into An ASP.NET Website: "

Twitter is a popular social networking web service for writing and sharing short messages. These tidy text messages are referred to as
tweets and are limited to 140 characters. Users can leave tweets and follow other users directly from Twitter's website or by using the Twitter API. Twitter's API makes
it possible to integrate Twitter with external applications. For example, you can use the Twitter API to display your latest tweets on your blog. A mom and pop online store could
integrate Twitter such that a new tweet was added each time a customer completed an order. And ELMAH, a popular open-source
error logging library, can be configured to send error notifications to Twitter.


Twitter's API is implemented over HTTP using the design principles of Representational State Transfer (REST).
In a nutshell, inter-operating with the Twitter API involves a client - your application - sending an XML-formatted message over HTTP to the server - Twitter's website. The
server responds with an XML-formatted message that contains status information and data. While you can certainly interface with this API by writing your own code to communicate
with the Twitter API over HTTP along with the code that creates and parses the XML payloads exchanged between the client and server, such work is unnecessary since there are
many community-created Twitter API libraries for a variety of programming frameworks.


This article shows how to integrate Twitter with an ASP.NET website using the Twitterizer library, which is a free,
open-source .NET library for working with the Twitter API. Specifically, this article shows how to retrieve your latest tweets and how to post a tweet using Twitterizer.
Read on to learn more!

Read More >

"

Saturday, January 9, 2010

New features of C# 4.0

New features of C# 4.0: "This article covers New features of C# 4.0. Article has been divided into below sections.

Introduction.
Dynamic Lookup.
Named and Optional Arguments.
Features for COM interop.
Variance.
Relationship with Visual Basic.
Resources.

Other interested readings…
22 New Features of Visual Studio 2008 for .NET Professionals
50 New Features of SQL Server 2008
IIS 7.0 New features

Introduction

It is now close to a year since Microsoft Visual C# 3.0 shipped as part of Visual Studio 2008. In the VS Managed Languages team we are hard at work on creating the next version of the language (with the unsurprising working title of C# 4.0), and this document is a first public description of the planned language features as we currently see them.

Please be advised that all this is in early stages of production and is subject to change. Part of the reason for sharing our plans in public so early is precisely to get the kind of feedback that will cause us to improve the final product before it rolls out.

Simultaneously with the publication of this whitepaper, a first public CTP (community technology preview) of Visual Studio 2010 is going out as a Virtual PC image for everyone to try. Please use it to play and experiment with the features, and let us know of any thoughts you have. We ask for your understanding and patience working with very early bits, where especially new or newly implemented features do not have the quality or stability of a final product. The aim of the CTP is not to give you a productive work environment but to give you the best possible impression of what we are working on for the next release.

The CTP contains a number of walkthroughs, some of which highlight the new language features of C# 4.0. Those are excellent for getting a hands-on guided tour through the details of some common scenarios for the features. You may consider this whitepaper a companion document to these walkthroughs, complementing them with a focus on the overall language features and how they work, as opposed to the specifics of the concrete scenarios.

C# 4.0

The major theme for C# 4.0 is dynamic programming. Increasingly, objects are “dynamic” in the sense that their structure and behavior is not captured by a static type, or at least not one that the compiler knows about when compiling your program. Some examples include

a. objects from dynamic programming languages, such as Python or Ruby

b. COM objects accessed through IDispatch

c. ordinary .NET types accessed through reflection

d. objects with changing structure, such as HTML DOM objects

While C# remains a statically typed language, we aim to vastly improve the interaction with such objects.

A secondary theme is co-evolution with Visual Basic. Going forward we will aim to maintain the individual character of each language, but at the same time important new features should be introduced in both languages at the same time. They should be differentiated more by style and feel than by feature set.

The new features in C# 4.0 fall into four groups:

Dynamic lookup

Dynamic lookup allows you to write method, operator and indexer calls, property and field accesses, and even object invocations which bypass the C# static type checking and instead gets resolved at runtime.

Named and optional parameters

Parameters in C# can now be specified as optional by providing a default value for them in a member declaration. When the member is invoked, optional arguments can be omitted. Furthermore, any argument can be passed by parameter name instead of position.

COM specific interop features

Dynamic lookup as well as named and optional parameters both help making programming against COM less painful than today. On top of that, however, we are adding a number of other small features that further improve the interop experience.

Variance

It used to be that an IEnumerable<string> wasn’t an IEnumerable<object>. Now it is – C# embraces type safe “co-and contravariance” and common BCL types are updated to take advantage of that.

Dynamic Lookup

Dynamic lookup allows you a unified approach to invoking things dynamically. With dynamic lookup, when you have an object in your hand you do not need to worry about whether it comes from COM, IronPython, the HTML DOM or reflection; you just apply operations to it and leave it to the runtime to figure out what exactly those operations mean for that particular object.

This affords you enormous flexibility, and can greatly simplify your code, but it does come with a significant drawback: Static typing is not maintained for these operations. A dynamic object is assumed at compile time to support any operation, and only at runtime will you get an error if it wasn’t so. Oftentimes this will be no loss, because the object wouldn’t have a static type anyway, in other cases it is a tradeoff between brevity and safety. In order to facilitate this tradeoff, it is a design goal of C# to allow you to opt in or opt out of dynamic behavior on every single call.

The dynamic type

C# 4.0 introduces a new static type called dynamic. When you have an object of type dynamic you can “do things to it” that are resolved only at runtime:

dynamic d = GetDynamicObject(…);
d.M(7);

The C# compiler allows you to call a method with any name and any arguments on d because it is of type dynamic. At runtime the actual object that d refers to will be examined to determine what it means to “call M with an int” on it.

The type dynamic can be thought of as a special version of the type object, which signals that the object can be used dynamically. It is easy to opt in or out of dynamic behavior: any object can be implicitly converted to dynamic, “suspending belief” until runtime. Conversely, there is an “assignment conversion” from dynamic to any other type, which allows implicit conversion in assignment-like constructs:

dynamic d = 7; // implicit conversion
int i = d; // assignment conversion

Dynamic operations

Not only method calls, but also field and property accesses, indexer and operator calls and even delegate invocations can be dispatched dynamically:

dynamic d = GetDynamicObject(…);
d.M(7); // calling methods
d.f = d.P; // getting and settings fields and properties
d[“one”] = d[“two”]; // getting and setting thorugh indexers
int i = d + 3; // calling operators
string s = d(5,7); // invoking as a delegate

The role of the C# compiler here is simply to package up the necessary information about “what is being done to d”, so that the runtime can pick it up and determine what the exact meaning of it is given an actual object d. Think of it as deferring part of the compiler’s job to runtime.

The result of any dynamic operation is itself of type dynamic.

Runtime lookup

At runtime a dynamic operation is dispatched according to the nature of its target object d:

COM objects

If d is a COM object, the operation is dispatched dynamically through COM IDispatch. This allows calling to COM types that don’t have a Primary Interop Assembly (PIA), and relying on COM features that don’t have a counterpart in C#, such as indexed properties and default properties.

Dynamic objects

If d implements the interface IDynamicObject d itself is asked to perform the operation. Thus by implementing IDynamicObject a type can completely redefine the meaning of dynamic operations. This is used intensively by dynamic languages such as IronPython and IronRuby to implement their own dynamic object models. It will also be used by APIs, e.g. by the HTML DOM to allow direct access to the object’s properties using property syntax.

Plain objects

Otherwise d is a standard .NET object, and the operation will be dispatched using reflection on its type and a C# “runtime binder” which implements C#’s lookup and overload resolution semantics at runtime. This is essentially a part of the C# compiler running as a runtime component to “finish the work” on dynamic operations that was deferred by the static compiler.

Example

Assume the following code:

dynamic d1 = new Foo();
dynamic d2 = new Bar();
string s;

d1.M(s, d2, 3, null);

Because the receiver of the call to M is dynamic, the C# compiler does not try to resolve the meaning of the call. Instead it stashes away information for the runtime about the call. This information (often referred to as the “payload”) is essentially equivalent to:

“Perform an instance method call of M with the following arguments:

1. a string

2. a dynamic

3. a literal int 3

4. a literal object null”

At runtime, assume that the actual type Foo of d1 is not a COM type and does not implement IDynamicObject. In this case the C# runtime binder picks up to finish the overload resolution job based on runtime type information, proceeding as follows:

1. Reflection is used to obtain the actual runtime types of the two objects, d1 and d2, that did not have a static type (or rather had the static type dynamic). The result is Foo for d1 and Bar for d2.

2. Method lookup and overload resolution is performed on the type Foo with the call M(string,Bar,3,null) using ordinary C# semantics.

3. If the method is found it is invoked; otherwise a runtime exception is thrown.

Overload resolution with dynamic arguments

Even if the receiver of a method call is of a static type, overload resolution can still happen at runtime. This can happen if one or more of the arguments have the type dynamic:

Foo foo = new Foo();
dynamic d = new Bar();

var result = foo.M(d);

The C# runtime binder will choose between the statically known overloads of M on Foo, based on the runtime type of d, namely Bar. The result is again of type dynamic.

The Dynamic Language Runtime

An important component in the underlying implementation of dynamic lookup is the Dynamic Language Runtime (DLR), which is a new API in .NET 4.0.

The DLR provides most of the infrastructure behind not only C# dynamic lookup but also the implementation of several dynamic programming languages on .NET, such as IronPython and IronRuby. Through this common infrastructure a high degree of interoperability is ensured, but just as importantly the DLR provides excellent caching mechanisms which serve to greatly enhance the efficiency of runtime dispatch.

To the user of dynamic lookup in C#, the DLR is invisible except for the improved efficiency. However, if you want to implement your own dynamically dispatched objects, the IDynamicObject interface allows you to interoperate with the DLR and plug in your own behavior. This is a rather advanced task, which requires you to understand a good deal more about the inner workings of the DLR. For API writers, however, it can definitely be worth the trouble in order to vastly improve the usability of e.g. a library representing an inherently dynamic domain.

Open issues

There are a few limitations and things that might work differently than you would expect.

· The DLR allows objects to be created from objects that represent classes. However, the current implementation of C# doesn’t have syntax to support this.

· Dynamic lookup will not be able to find extension methods. Whether extension methods apply or not depends on the static context of the call (i.e. which using clauses occur), and this context information is not currently kept as part of the payload.

· Anonymous functions (i.e. lambda expressions) cannot appear as arguments to a dynamic method call. The compiler cannot bind (i.e. “understand”) an anonymous function without knowing what type it is converted to.

One consequence of these limitations is that you cannot easily use LINQ queries over dynamic objects:

dynamic collection = …;

var result = collection.Select(e => e + 5);

If the Select method is an extension method, dynamic lookup will not find it. Even if it is an instance method, the above does not compile, because a lambda expression cannot be passed as an argument to a dynamic operation.

There are no plans to address these limitations in C# 4.0.

Named and Optional Arguments

Named and optional parameters are really two distinct features, but are often useful together. Optional parameters allow you to omit arguments to member invocations, whereas named arguments is a way to provide an argument using the name of the corresponding parameter instead of relying on its position in the parameter list.

Some APIs, most notably COM interfaces such as the Office automation APIs, are written specifically with named and optional parameters in mind. Up until now it has been very painful to call into these APIs from C#, with sometimes as many as thirty arguments having to be explicitly passed, most of which have reasonable default values and could be omitted.

Even in APIs for .NET however you sometimes find yourself compelled to write many overloads of a method with different combinations of parameters, in order to provide maximum usability to the callers. Optional parameters are a useful alternative for these situations.

Optional parameters

A parameter is declared optional simply by providing a default value for it:

public void M(int x, int y = 5, int z = 7);

Here y and z are optional parameters and can be omitted in calls:

M(1, 2, 3); // ordinary call of M
M(1, 2); // omitting z – equivalent to M(1, 2, 7)
M(1); // omitting both y and z – equivalent to M(1, 5, 7)

Named and optional arguments

C# 4.0 does not permit you to omit arguments between commas as in M(1,,3). This could lead to highly unreadable comma-counting code. Instead any argument can be passed by name. Thus if you want to omit only y from a call of M you can write:

M(1, z: 3); // passing z by name

or

M(x: 1, z: 3); // passing both x and z by name

or even

M(z: 3, x: 1); // reversing the order of arguments

All forms are equivalent, except that arguments are always evaluated in the order they appear, so in the last example the 3 is evaluated before the 1.

Optional and named arguments can be used not only with methods but also with indexers and constructors.

Overload resolution

Named and optional arguments affect overload resolution, but the changes are relatively simple:

A signature is applicable if all its parameters are either optional or have exactly one corresponding argument (by name or position) in the call which is convertible to the parameter type.

Betterness rules on conversions are only applied for arguments that are explicitly given – omitted optional arguments are ignored for betterness purposes.

If two signatures are equally good, one that does not omit optional parameters is preferred.

M(string s, int i = 1);
M(object o);
M(int i, string s = “Hello”);
M(int i);

M(5);

Given these overloads, we can see the working of the rules above. M(string,int) is not applicable because 5 doesn’t convert to string. M(int,string) is applicable because its second parameter is optional, and so, obviously are M(object) and M(int).

M(int,string) and M(int) are both better than M(object) because the conversion from 5 to int is better than the conversion from 5 to object.

Finally M(int) is better than M(int,string) because no optional arguments are omitted.

Thus the method that gets called is M(int).

Features for COM interop

Dynamic lookup as well as named and optional parameters greatly improve the experience of interoperating with COM APIs such as the Office Automation APIs. In order to remove even more of the speed bumps, a couple of small COM-specific features are also added to C# 4.0.

Dynamic import

Many COM methods accept and return variant types, which are represented in the PIAs as object. In the vast majority of cases, a programmer calling these methods already knows the static type of a returned object from context, but explicitly has to perform a cast on the returned value to make use of that knowledge. These casts are so common that they constitute a major nuisance.

In order to facilitate a smoother experience, you can now choose to import these COM APIs in such a way that variants are instead represented using the type dynamic. In other words, from your point of view, COM signatures now have occurrences of dynamic instead of object in them.

This means that you can easily access members directly off a returned object, or you can assign it to a strongly typed local variable without having to cast. To illustrate, you can now say

excel.Cells[1, 1].Value = "Hello";

instead of

((Excel.Range)excel.Cells[1, 1]).Value2 = "Hello";

and

Excel.Range range = excel.Cells[1, 1];

instead of

Excel.Range range = (Excel.Range)excel.Cells[1, 1];

Compiling without PIAs

Primary Interop Assemblies are large .NET assemblies generated from COM interfaces to facilitate strongly typed interoperability. They provide great support at design time, where your experience of the interop is as good as if the types where really defined in .NET. However, at runtime these large assemblies can easily bloat your program, and also cause versioning issues because they are distributed independently of your application.

The no-PIA feature allows you to continue to use PIAs at design time without having them around at runtime. Instead, the C# compiler will bake the small part of the PIA that a program actually uses directly into its assembly. At runtime the PIA does not have to be loaded.

Omitting ref

Because of a different programming model, many COM APIs contain a lot of reference parameters. Contrary to refs in C#, these are typically not meant to mutate a passed-in argument for the subsequent benefit of the caller, but are simply another way of passing value parameters.

It therefore seems unreasonable that a C# programmer should have to create temporary variables for all such ref parameters and pass these by reference. Instead, specifically for COM methods, the C# compiler will allow you to pass arguments by value to such a method, and will automatically generate temporary variables to hold the passed-in values, subsequently discarding these when the call returns. In this way the caller sees value semantics, and will not experience any side effects, but the called method still gets a reference.

Open issues

A few COM interface features still are not surfaced in C#. Most notably these include indexed properties and default properties. As mentioned above these will be respected if you access COM dynamically, but statically typed C# code will still not recognize them.

There are currently no plans to address these remaining speed bumps in C# 4.0.

Variance

An aspect of generics that often comes across as surprising is that the following is illegal:

IList<string> strings = new List<string>();
IList<object> objects = strings;

The second assignment is disallowed because strings does not have the same element type as objects. There is a perfectly good reason for this. If it were allowed you could write:

objects[0] = 5;
string s = strings[0];

Allowing an int to be inserted into a list of strings and subsequently extracted as a string. This would be a breach of type safety.

However, there are certain interfaces where the above cannot occur, notably where there is no way to insert an object into the collection. Such an interface is IEnumerable<T>. If instead you say:

IEnumerable<object> objects = strings;

There is no way we can put the wrong kind of thing into strings through objects, because objects doesn’t have a method that takes an element in. Variance is about allowing assignments such as this in cases where it is safe. The result is that a lot of situations that were previously surprising now just work.

Covariance

In .NET 4.0 the IEnumerable<T> interface will be declared in the following way:

public interface IEnumerable<out T> : IEnumerable
{
IEnumerator<T> GetEnumerator();
}

public interface IEnumerator<out T> : IEnumerator
{
bool MoveNext();
T Current { get; }
}

The “out” in these declarations signifies that the T can only occur in output position in the interface – the compiler will complain otherwise. In return for this restriction, the interface becomes “covariant” in T, which means that an IEnumerable<A> is considered an IEnumerable<B> if A has a reference conversion to B.

As a result, any sequence of strings is also e.g. a sequence of objects.

This is useful e.g. in many LINQ methods. Using the declarations above:

var result = strings.Union(objects); // succeeds with an IEnumerable<object>

This would previously have been disallowed, and you would have had to to some cumbersome wrapping to get the two sequences to have the same element type.

Contravariance

Type parameters can also have an “in” modifier, restricting them to occur only in input positions. An example is IComparer<T>:

public interface IComparer<in T>
{
public int Compare(T left, T right);
}

The somewhat baffling result is that an IComparer<object> can in fact be considered an IComparer<string>! It makes sense when you think about it: If a comparer can compare any two objects, it can certainly also compare two strings. This property is referred to as contravariance.

A generic type can have both in and out modifiers on its type parameters, as is the case with the Func<…> delegate types:

public delegate TResult Func<in TArg, out TResult>(TArg arg);

Obviously the argument only ever comes in, and the result only ever comes out. Therefore a Func<object,string> can in fact be used as a Func<string,object>.

Limitations

Variant type parameters can only be declared on interfaces and delegate types, due to a restriction in the CLR. Variance only applies when there is a reference conversion between the type arguments. For instance, an IEnumerable<int> is not an IEnumerable<object> because the conversion from int to object is a boxing conversion, not a reference conversion.

Also please note that the CTP does not contain the new versions of the .NET types mentioned above. In order to experiment with variance you have to declare your own variant interfaces and delegate types.

COM Example

Here is a larger Office automation example that shows many of the new C# features in action.

using System;
using System.Diagnostics;
using System.Linq;
using Excel = Microsoft.Office.Interop.Excel;
using Word = Microsoft.Office.Interop.Word;

class Program
{
static void Main(string[] args) {
var excel = new Excel.Application();
excel.Visible = true;

excel.Workbooks.Add(); // optional arguments omitted

excel.Cells[1, 1].Value = "Process Name"; // no casts; Value dynamically
excel.Cells[1, 2].Value = "Memory Usage"; // accessed

var processes = Process.GetProcesses()
.OrderByDescending(p =&gt; p.WorkingSet)
.Take(10);

int i = 2;
foreach (var p in processes) {
excel.Cells[i, 1].Value = p.ProcessName; // no casts
excel.Cells[i, 2].Value = p.WorkingSet; // no casts
i++;
}

Excel.Range range = excel.Cells[1, 1]; // no casts

Excel.Chart chart = excel.ActiveWorkbook.Charts.
Add(After: excel.ActiveSheet); // named and optional arguments

chart.ChartWizard(
Source: range.CurrentRegion,
Title: "Memory Usage in " + Environment.MachineName); //named+optional

chart.ChartStyle = 45;

chart.CopyPicture(Excel.XlPictureAppearance.xlScreen,
Excel.XlCopyPictureFormat.xlBitmap,
Excel.XlPictureAppearance.xlScreen);

var word = new Word.Application();
word.Visible = true;

word.Documents.Add(); // optional arguments

word.Selection.Paste();
}
}

The code is much more terse and readable than the C# 3.0 counterpart.

Note especially how the Value property is accessed dynamically. This is actually an indexed property, i.e. a property that takes an argument; something which C# does not understand. However the argument is optional. Since the access is dynamic, it goes through the runtime COM binder which knows to substitute the default value and call the indexed property. Thus, dynamic COM allows you to avoid accesses to the puzzling Value2 property of Excel ranges.

Relationship with Visual Basic

A number of the features introduced to C# 4.0 already exist or will be introduced in some form or other in Visual Basic:

· Late binding in VB is similar in many ways to dynamic lookup in C#, and can be expected to make more use of the DLR in the future, leading to further parity with C#.

· Named and optional arguments have been part of Visual Basic for a long time, and the C# version of the feature is explicitly engineered with maximal VB interoperability in mind.

· NoPIA and variance are both being introduced to VB and C# at the same time.

VB in turn is adding a number of features that have hitherto been a mainstay of C#. As a result future versions of C# and VB will have much better feature parity, for the benefit of everyone.

Resources

All available resources concerning C# 4.0 can be accessed through the C# Dev Center. Specifically, this white paper and other resources can be found at the Code Gallery site. Enjoy!


"

Friday, January 8, 2010

Doing It Wrong

Doing It Wrong: "

Enterprise Systems, I mean. And not just a little bit,
either. Orders of magnitude wrong. Billions and billions of dollars worth of
wrong.
Hang-our-heads-in-shame wrong. It’s time to stop the madness.


These last five years at Sun, I’ve been lucky: I live in the Open-Source
and “Web 2.0” communities, and at the same time I’ve been given
significant quality
time with senior IT people among our Enterprise customers.


What I’m writing here is the single most important take-away from my Sun
years, and it fits in a sentence: The community of developers whose work you
see on the Web, who probably don’t know what ADO or UML or JPA even stand
for, deploy better systems at less cost in less
time
at lower risk than we see in the Enterprise. This is true even
when you factor in the greater flexibility and velocity of
startups.


This is unacceptable.
The Fortune 1,000 are bleeding money and missing huge opportunities to excel
and compete.
I’m not going to say that these are low-hanging fruit,
because if it were easy to bridge this gap, it’d have been bridged. But the
gap is so big, the rewards are so huge, that it’s time for some serious
bridge-building investment.
I don’t know what my future is right now, but this seems
by far the most important thing for my profession to be working on.


The Web These Days


It’s like this: The time between having an idea and its public launch
is measured in days not months, weeks not years. Same for
each subsequent release cycle. Teams are small. Progress is iterative. No
oceans are boiled, no monster requirements documents written.


And what do you get? Facebook. Google. Twitter. Ravelry. Basecamp.
TripIt. GitHub. And on and on and on.


Obviously, the technology matters. This isn’t the place for details, but
apparently the winning mix includes dynamic languages and Web frameworks and
TDD and REST and Open Source and NoSQL at varying levels of
relative importance.


More important is the culture: iterative development, continuous
refactoring, ubiquitous unit testing, starting small, gathering user
experience before it seems reasonable.
All of which, to be fair, I suppose had its roots
in last decade’s Extreme and Agile movements. I don’t hear a lot of talk
these days from anyone claiming to “do Extreme” or “be Agile”. But then, in
Web-land for damn sure I never hear any talk about large
fixed-in-advance specifications, or doing the UML first, or development cycles
longer than a single-digit number of weeks.


In The Enterprise


I’m not going to recite the
statistics
about the proportions of big projects that fail to work out, or flog moribund
horses like the
failed
FBI system
or Britain’s
monumentally-troubled
(to the tune of billions)
NHS
National Programme for IT
. For one thing, the litany of disasters in the
private sector is just as big in the aggregate and the batting average isn’t
much better; it’s just that businesses can sweep the ashes under the
carpet.


If you enjoy this sort of stuff, I recommend Michael Krigsman’s
IT Project Failures
column over at ZDNet. Also,
Bruce Webster is very good.
And for some more gloomy numbers, check out
The
CHAOS Report 2009 on IT Project Failure
.


Amusingly, all the IT types who write about this agree that the problem is
“excessive complexity”, whatever that means. Predictably, many
of them follow the trail-of-tears story with a pitch for their own
methodology, which they say will
fix the problem. And even if we therefore suspect them of cranking up the
gloom-&-doom knob a bit, the figures remain distressing.


So, what is to be done?


Plan A: Don’t Build Systems


The best thing, of course, is to simply not build your own systems. As
many in our industry have pointed out, perhaps most eloquently
Nicholas Carr,
everything would be better if we could do IT the way we do electricity; hook
up to the grid, let the IT utility run it all, and get billed per unit
of usage.


This is where all the people now running
around shouting “Cloud! Cloud! Cloud!” are trying to go. And it’s
where Salesforce.com, for example, already is.


If you must run systems in-house, don’t engineer them, get ’em pre-cooked
from Oracle or SAP or whoever. I can’t imagine any nonspecialist organization
for whom it would make sense to build an HR or accounting application from
scratch at this point in history.


Of course, we’re not in the Promised Land yet. I’m actually surprised that
Salesforce isn’t a lot bigger than it is; a variety of things are holding back
the migration to the utility model. Also, you hear tales of failed
implementations at the SAP and Oracle app-levels too, especially CRM. And
Oracle is well-known to be ferociously hard at work on a wholesale revision of
the app stack with the
Fusion
Applications
. But still, even if things aren’t perfect, nobody is
predicting a return to hand-crafted Purchasing or Travel-Expense
systems. Thank goodness.


But Sometimes You Have To


I don’t believe we’ll ever go to a pure-utility model for IT. Every
world-class business has some sort of core competence, and there are good
arguments that sometimes, you should implement your own systems around
yours.
My favorite example, of the ones I’ve seen over the past few years,
is the NASDAQ trading system, which handles a ridiculous number of
transactions in 6½ hours every trading day and pushes certain well-known
technologies to places that I’d have flatly sworn were impossible if I hadn’t
seen it.


Here’s a negative example: One of the world’s most ferocious competitive
landscapes is telecoms, which these days means mobile telecoms. One way a
telecom might
like to compete would be to provide a better customer experience: billing,
support, and so on. But to some degree they can’t, because many of them have
outsourced much of that stuff to
Amdocs.


Given all the colossal high-visibility failures like the ones I mentioned
earlier, what responsible telecom executive would authorize going ahead with
building an in-house alternative? But at some level that’s insane; if your
business is customer service, how can you bypass
an opportunity to compete by offering better customer service? The telecom
networks around where I live seem to put most of their strategic investments
into marketing, which is a bit sad.


Plan B: Do It Better


Here’s a thought experiment: Suppose you asked one of the
blue-suit
solution providers
to quote you on building Ravelry or
Twitter or Basecamp. What would the costs be like?
And how much confidence would you have in a good
result? Consider the same questions for a new mobile-network billing
system.


The point is that that kind of thing simply cannot be built if you
start with large formal specifications and fixed-price contracts and
change-control procedures and so on. So if your enterprise wants the sort of
outcomes we’re seeing on the Web
(and a lot more should), you’re going to have to adopt some of the
cultures and technologies that got them built.


It’s not going to be easy; Enterprise IT has spent decades growing a
defensive culture based on the premise that you only get noticed when you screw up,
so that must be avoided at all costs.


I’m not the only one thinking about how we can get Enterprise Systems
unjammed and make them once again part of the solution, not part of the
problem. It’s a good thing to be thinking about.


"

Saturday, December 26, 2009

How to make ASP.NET 3rd party controls run faster

How to make ASP.NET 3rd party controls run faster: "1. Abstract
The following document will explore the basics of enhancing 3rd party ASP.NET components performance by leveraging the Empty Client (an ASP.NET extension) pipeline.
Subtitle: 


Overview for ASP.NET based components that explores the basics of enhancing 3rd party ASP.NET components performance by leveraging the Empty Client (an ASP.NET..."

20 Must Read LINQ, WCF, Expression Web, VSTS and Windows Forms articles on DotNetCurry – 2009

20 Must Read LINQ, WCF, Expression Web, VSTS and Windows Forms articles on DotNetCurry – 2009: "In this post, we have compiled 20 Must Read articles that were published in the year 2009 and focus around technologies like LINQ, VSTS, Expression Web, WCF and Windows Forms.


"