August 2007 - Posts

C# 3.0 - What's New : {Implicit}-Part1

Recent development in my technical life is that, started working out with Orcas Beta 2. So, thought to blog about the latest happenings with C# language. The idea emerged to start a series of posts related to C# new features. This is the first of ever such kind of blogging specific to a topic.

C# 3.0 has many-a-new features. To start with, let me take a concept of Implicitly Typed Variables.

Implicitly Typed Variables

In the good old days, the developer has to worry about the type of the variable. Say for instance, whether to use long or double for a counter. Here all that we observe is that the language that is built upon is the type specific. Hence forth the developer is not required to define the type of the variable at the time of declaration, but it is the task of the compiler to decide what type of the object the variable is. All that the developer has to do is that, use the var keyword while declaring the variable, similar to that of JScript or Visual Basic style. Hey!!! Stop!!!!! don't get confuse with the type of VAR variables declared at JScript or Visual basic.

Let's first discuss the difference between VAR variables at JScript and VAR variables of C#

VAR JScript VAR C#
This is of no type The type of the variable is defined by the value declared and decided at the compile time
Technically have no type. Can consider of limited types, namely, string literal, numeric, boolean Type agnostic, have specific predefined formats
Type conversion is coercion Type casting is simple and handled by CLR
No mechanism for parsing explicit functions for parsing to specific type

Now, let us see the difference between the language specific VAR of VisualBasic 6.0 and C# 3.0

VAR in VB (but not .NET) VAR in C# 3.0
By definition, these are Variant Type of the variable is defined at the compile time
Could be any allowed type from with in the known types of the language Type is decided by the value associated with the variable
Largest among all the known data tydpes Size depends on the type of the value initialised

To summarize, the variables declared in C# 3.0 are type specific, thou used the key word VAR, during the declaration. Thus, we can conclude that the compiler is the responsible point to decide the type of the variable. Hence we can say with comfort that, the variables from C# 3.0 are Implicitly Typed variables.

Some examples as mentioned below.

            var vIntVal = 10; // This will be the System.Int32 type
            var vLongVal = 10000000000; // This will be the System.Int64 type
            var vDoubleVal = 10.0; // This will be the System.Double type
            var vFloatVal = 10.0f; // This will be the System.Single type
            float vFlVal = 10.0f; // Thou defined using float key word, but inherits from Struct System.Single 
            var vStrVal = "String Value ";  // This will be the System.String type

So, from the above declarations, it is pretty clear that the variable is defined by the value associated during the declaration. The type is not just limited to the kind of data types as explained above, but you can extend this to any type of the variable that you use while writing code for iterations, similar such as foreach. Below is the example for other known types.

            foreach (var vTable in ds.Tables) // Implicitly declared a variable of Data Table Type
            {
                foreach (var vRow in ((DataTable) vTable).Rows) // Implicit declaration of DataRow variable
                {

                }
            }

By using such, one can extend any extent. The limit is the imagination of the developer. What do you say?

Source:

1) http://cobdev.cob.isu.edu/psb/jscript/306.htm for JScript
2) http://www.1sayfa.com/1024/diger/vb/ch07.htm for Visual Basic 6.0 Datatypes

del.icio.us Tags: , , , ,
Posted by Chakravarthy | with no comments
Filed under: , , , ,

Tafiti Search Engine from Microsoft

Tafiti, which means "do research" in Swahili, is an experimental search front-end from Microsoft, designed to help people use the Web for research projects that span multiple search queries and sessions by helping visualize, store, and share research results. Tafiti uses both Microsoft Silverlight and Live Search to explore the intersection of richer experiences on the Web and the increasing specialization of search.

image My experience with Tafiti is awesome. It is a great visual treat. The features as of now I found to be great is the type specific.

In other words, as you could see here when you search for any topic, you could filter them specific to the icon displayed here. You could filter the RSS feeds, Blogs, Images, News, as of now. Probably, they would come out with lot more.

All these days am a die-hard fan of godark.us due to the search in black for google, not any more. Secondly, am not sure about the content relevance percentage of the search. Time will prove the statistics.

image

Apart of that it also has the mechanism to save the search onto the right side of the visible area.

So that you don't require remember for a specific search.

True that, it installs the Silverlight component. But silver light is going to be the future for streaming videos on web.

And one more thing, can I consider this as stack of my searches????

What do you say?
del.icio.us Tags: ,
Posted by Chakravarthy | 2 comment(s)
Filed under:

Increase Web Pages Response time - tip

For the ASP.NET pages that has no user input it is a best practice to have the page register with EnableViewState=“false”. This will increase the response time to 200% of the default.

Along with that, you can also do the one more important is that, anyhow these pages have no user input. Secondly, these will have data that is read-only from database. Thus, you are sure that there is no activity from the user that could be saved onto disk. Perhaps the user might work with the data that is available on the page.

Hence, keeping all the above point in mind, by setting the session’s state to read-only makes the WebPages more effective and the response time increases drastically to about another 200%. Think this and change your web page attributes from the next time onwards

del.icio.us Tags: , , ,

Technorati Tags: , ,
Posted by Chakravarthy | with no comments
Filed under: ,

Runtime Polymorphism

One of the frequently seen situations from a technical standpoint in a large scale of Business Layer objects is, invoking methods from different objects when they contain same method name. Today, am going to make it simple to give an example for Runtime Polymorphism. Leave your comments if am mistaken

At this stage, I don’t think to mention about "Polymorphism", as hope that you are aware of how polymorphic behavior can be fused using C#. If you want a start up, in simple words, implementation of one Method with many definitions, as mentioned below.

class Employee
{
/// <summary>
/// Invoked for the Regular salaried employes
/// </summary>
/// <param name="intEmpId">Employee ID</param>
/// <param name="intAbscentDays">Number of days</param>
/// <returns></returns>

public long CalculateSal(int intEmpId, int intAbscentDays)
{
return (GetEmpSal(intEmpId) * (GetWorkingDays(DateTime.Now.Month) - intAbscentDays));
}

/// <summary>

/// Invoked for the employees, who work as Daily wage
/// </summary>
/// <param name="lSalPerDay">Salary per day</param>
/// <param name="intDays">For number of days</param>
/// <returns></returns>
public long CalculateSal(long lSalPerDay, int intDays)
{
return lSalPerDay * intDays;
}
}

A simple way of invoking is as mentioned below.

Employee eTe = new Employee();

long lSal = eTe.CalculateSal(124, 2);
long lSal = eTe.CalculateSal(678.35, 18);

So, by now, you are clear how to write polymorphic method and as well as how to use. Let’s jump to how you can make the Runtime Polymorphism.

To continue the discussion, first we need to know that there are 2 basic types of polymorphism. They are, Overloading, referred as Compile time polymorphism, and Overriding also called as Run-Time polymorphism. What you have seen above is the first kind of polymorphism. The second type is referred as late binding. In other words, the selection of the method for execution at runtime depends on the reference of the actual object that is triggering the invoking of the method. Now let's explore that with some example.

Let us take a small class, as mentioned below with few properties. This class acts as a base class for us.

    public class EmpNames
    {
        public string FirstName { get; set; }
        public string MiddleName { get; set; }
        public string LastName { get; set; }
    }

We will now inherit this into the following classes. Observe that the both classes doesn't have any direct relation with each other and can be instantiated as is.

    /// <summary>
    /// This class calculate the wages for given number of days
    /// </summary>
    public class Wages : EmpNames 
    {
        /// <summary>
        /// This will calculate the wages for the employees
        /// </summary>
        /// <param name="Params">Wage per Day, Number of Working days in a month</param>
        /// <returns> WagePerDay * WorkingDays </returns>
        public double CalculateSalary(ArrayList Params)
        {
            return double.Parse(Params[0].ToString()) * int.Parse(Params[1].ToString());
        }
    }


    /// <summary>
    /// This class will calculate the salary
    /// </summary>
    public class Salried : EmpNames
    {
        /// <summary>
        /// This will calculate the salary for the employees
        /// </summary>
        /// <param name="Params">Working days Per Month, Leaves, Salary Per Month</param>
        /// <returns> Full Salary in case no value for Leaves. Other case, (SalaryPerMonth/WorkingDays) * (WorkingDays - Leaves) </returns>
        public double CalculateSalary(ArrayList Params)
        {
            double dSal=double.Parse(Params[2].ToString());
            int intLeaves = int.Parse(Params[1].ToString());
            if (!intLeaves.Equals(0))
            {
                int intWrkDays = int.Parse(Params[0].ToString());
                dSal = (dSal / intWrkDays) * (intWrkDays - intLeaves);
            }
            return dSal;
        }
    }

Now that we have these two classes, We can write our code to instantiate them as individual. But the point of this post is to describe the "RunTime Polymorphism". Before we go further, note that, each class has the method "CalculateSalary" and as they are not directly related, you can instantiate them with out any hassle.

            EmpNames empObj;
            ArrayList alValues = new ArrayList();
            alValues.Add(30); //Just add all the fields as this
            bool bSalaried = true; //am using this variable for validation of emp

            if (bSalaried) //Validating whether Salaried or Wages 
                empObj = new Salried();
            else
                empObj = new Wages();
After executing the above lines of code, you are sure about the type of the variable empObj. This is Runtime initiating the object. But this is not the purpose of our current topic.
            double dVal;

            //The below line will throw compile time error
            //dVal = empObj.CalculateSalary(alValues);
            dVal = ((Wages) empObj).CalculateSalary(alValues);

What do you see from the last line of the above code? Did you find that the method invoked is from a class type. Now, think that, what if the class is being instantiated as Salaried and the last line is being invoked?

This is called as RunTime Polymorphism.

del.icio.us Tags: , ,


-----------------------
 Declaimer: What ever you read here is out of my own experience. No one shall be made responsible for the contents and issues that are mentioned here. If you have something to share in person on this post, pl drop me a mail at dskcheck@gmail.com with the title in the subject.

Posted by Chakravarthy | with no comments

Save Power by using Google in Black

Would like to bring this to your attention that, while searching at Google you could save some energy. Would you like to know “How?”, read further, not interested !!! Just Move on to next message.

Consider that you query at Google.com (with White background as it is by default). And white pixels as full background will consume 74 watts. You seek some info at Google, and the search results remain on your screen for more than 10 seconds.

The statistics from Google states that an approximate hit count for a day is at around 200 Million, that means there are about such huge number of people who are hitting Google by default with White Background. Resulting to consume the energy of 74 watts with every user. For your information on general CRT, the white pixels consume 74 watts, where as the black pixels consume at about 59 watts. So when you calculate mathematically, you would save about 15 watts, when compared to white background with black, causing lots of saving at the radiation from CRTs, Cathode Ray Tubes. But this is not true with LCD Screens, Liquid Crystal Display Screens. The LCDs will consume the same amount of energy when compared to both Black and White.

So, for the fact of figures, if 200 Million people use Black background Google instead of White background, estimate how much power saving??? And one more thing, you might not have all the 200 Million hits from the system that is attached with CRT Screens. When practically speaking, we see more CRT display screens than LCD screens. Hence request you to save energy, as an old saying echo’s in my mind as, “A penny saved is a penny earned”. In similar, “Energy saved is Energy Produced”

The alternatives for “White Background Google” is ..

1) 07designs.com/gdark => This has some script that will install as browser plugin

2) Searchincolors.com => You can search in any color that you like for Google.com, as background, foreground, blah, blah,..

3) Godark.us => has many other features, I recommend this due to the extra features

4) Jabago.com => thou not high funda, but meaningful

5) Ninja.com => simple to remember

6) Google-black.blogspot.com => You can write your own Google, as this blog. Inspire from this blog, can you create one such??

7) Trek3d.com/black => what are your comments on this???

Finally, any other recommendations towards “Googling in Black”?

Technorati Tags: ,
Posted by Chakravarthy | with no comments
Filed under: ,