Windows 8 & WinRT Library

Well I initially pretend to know about the new cool WinRT stuff but then someone already did it much better than I could. So here is one of the very good explaination on WinRT

WinRT demystified
Posted on 15 Sep 2011 by Miguel de Icaza
“…..

WinRT

WinRT is a new set of APIs that have the following properties:

It implements the new Metro look.
Has a simple UI programming model for Windows developers (You do not need to learn Win32, what an HDC, WndProc or LPARAM is).
It exposes the WPF/Silverlight XAML UI model to developers.
The APIs are all designed to be asynchronous.
It is a sandboxed API, designed for creating self-contained, AppStore-ready applications. You wont get everything you want to create for example Backup Software or Hard Disk Partitioning software.
The API definitions is exposed in the ECMA 335 metadata format (the same one that .NET uses, you can find those as “.winmd” files).
WinRT wraps both the new UI system as well as old Win32 APIs and it happens that this implementation is based on top of COM.

…..”

SOURCE : http://tirania.org/blog/archive/2011/Sep-15.html

—————————————————–

Enjoy! Oh and me being me , I have already secured my interest in WinRT via purchase of winrt.info :P

Programming Languages Review : ASP.net vs. PHP | web

In the world of web development, the choice of which development language to use commonly comes down to two popular choices. Web applications, specifically those relying on back end databases, are typically being created using either Microsoft’s ASP.Net language, or the Open Source alternative language of PHP. Reasons why one might choose one over the other can include: The cost of development tools, or availability of such tools, or even ones comfort level with the Open Source initiative. The goal of this article is to provide some perspective on reasons why one might choose one over the other.

Active Server Pages or ASP has long been an option for creating dynamic web content. Active Server Pages facilitates the ability to use databases such as Access or SQL just to name a few, to create dynamic, feature rich websites. The work going on behind the scenes in serving up the dynamic content is being done at the server level by the Active Server Pages source code. Microsoft has spent a great deal of time and resources promoting their .Net family of programming languages of which ASP.Net is a member. In order to develop with ASP.Net one must obtain the extremely expensive Microsoft Visual Studio Programming Suite. While expensive, Visual Studio is an asset to any programmer due to its vast amount of features. As with all of Microsoft’s products, support and updates are constantly made available for ASP.Net. The shear amount of features that Microsoft packs into Visual Studio, coupled with Microsoft’s extensive support make certainly make ASP.Net an attractive solution for any corporation’s web development needs, but the cost can be prohibitive, if not impossible to afford for the individual web developer.

PHP which is in its 5th revision now, is an Open Source web development language that also facilitates the creation of feature rich, dynamic websites that can use databases. Being Open Source means simply that PHP isn’t owned by anyone. Just as with Active Server Pages, the work going on behind the scenes of serving up the dynamic web content is being done by PHP at the server level. As with most Open Source products, the resources available to a PHP developer are free of charge. This makes PHP extremely attractive to the independent web developer. There are some commercial quality development suites available from companies like Zend, but there is also wealth of free resources just a Google Search away. Because there is really no corporate entity behind PHP, support and development on PHP is done by the community of its users and developers themselves. Surprisingly this does not seem to adversely affect the ability to find support for PHP.

All in all, ASP.Net and PHP are both excellent options, offering basically the same functionality. Whether the decision comes down to the cost of initial investment, or the comfort level one has regarding Open Source, or something else entirely, the end result depends upon the mastery of whichever language is chosen.

C# Programming | Switch

After a few days of non programming topics , let me welcome you back on the programming article. Today we shall take a look at C# switch , a way of making decisions. We have already gone through a few decision making methods , such as if-else. If you have not , pls take a look at here. Today , we will take a look at another way of making decisions.

Switch Syntax

  Switch(aVariable)
    {
       case something:
           .....;
           break;
       case something:
           .....;
           break;
    }

The way the switch statement works is simple. All you have to do is give it a variable , and then the possible values of it. If it matches the value , “case” will execute the comments below and ends with break keyword. Look at the example given below.

Switch Example

                int result = sumNumbers();

                switch(result)
                {
                    case 2:
                        finalResult = 2;
                        break;
                    case 3:
                        finalResult = 3;
                        break;
                    case 4:
                        finalResult = 4;
                        break;
                    case 5:
                        finalResult = 5;
                        break;
                    case 6:
                        finalResult = 6;
                        break;
                    case 7:
                        finalResult = 7;
                        break;
                    case 8:
                        finalResult = 8;
                        break;
                    case 9:
                        finalResult = 9;
                        break;
                    case 10:
                        finalResult = 10;
                        break;
                    case 11:
                        finalResult = 11;
                        break;
                    case 12:
                        finalResult = 12;
                        break;
                }

So if the “aVariable” name were to be equaled to 1 , finalResult would be assigned the value of 1. Of course , it is ridiculous to do this in practice. You might as well get the value directly from aVariable but we are talking about an example here. The only problem , as far as I can see , would be forgetting the “break” at the end of the case. hard to go wrong with this one.

Conclusion to Switch

Hope you learn something about C# and Switch in particular today , just as I have. Thank you and have a nice day!

More C# Functions | Prarmeters | Out & Ref | parameters

More of Function Parameters

Lets look into detail of two more parameters in C# functions , out and ref. Of course , we have seen the usual stuff here. Perhaps we could take a brief look into it again and talk about the difference between variable scope , which I remember , have been posted before too. Nonetheless , lets start.

int userAge; //variable outside the function getAge()

public int getAge(int userId)
{
   int userAge; //variable local to the function getAge()
   // codes to get the age from id
   return userAge;
}

userAge = getAge(12);

As you can see from my comments , although there are two variables called “userAge” , it doesn’t matter , although as a good programming practice , they should have been given different names. It is because on of them is only within the function while the other is within the class or namespace. And of course , the function returns an integer back to the caller. Suppose you want to return two variables , how do we go about doing that? You can only return one value if you write it as above. It won’t work if you coded return statement twice. But suppose you must return two variables.

Function With “out” Parameters

int userAge; //variable outside the function getAge()
int userEnglishGrade;

public void getInfo(out int userAge , out userEnglishGrade)
{
   userAge = 20;
   userEnglishGrade = 2;
}

getInfo(out userAge , out userEnglishGrade);

Console.WrintLN(userAge); //prints out 20
Console.WrintLN(userEnglishGrade); //prints out 2

As you can see , by using out , I can return the two variables , after assigning them with respective values. Of course , it doesn’t return anything because it is a “void” method. Pls take not that my out variables , userAge and userEnglishGrade were not initialised. They were only declared. Initializing takes place in the function which then returns them to the caller , in this case , the program. We now take a look at the parameter using ref keyword.

Function With “ref” Parameters

int userAge = 10; //variable outside the function getAge()
int userEnglishGrade = 2;

public void getInfo(ref int userAge , ref userEnglishGrade)
{
   userAge = 20;
   userEnglishGrade = 3;
}

Console.WrintLN(userAge); //prints out 10
Console.WrintLN(userEnglishGrade); //prints out 2

getInfo(ref userAge , ref userEnglishGrade);

Console.WrintLN(userAge); //prints out 20
Console.WrintLN(userEnglishGrade); //prints out 3

It looks almost the same as the out example above with a few exceptions. With ref , you are going to have to initialize the variable before calling the function whereas with out , you do so within the function. What ref does is that the address of the variable passed on is used to make the changes , which means the variable is directly updated within the function. If you have done any C programming before and it sounds similar to pointers , well then it is. In any case , for most of the time , you would probably be using the standard function with wither void or return.

Function Parameters Conclusion

Hope this clear up on the function parameters in C#. It isn’t as easy as my previous posts so if you didn’t get it the first time , don’t give up! Read , again and again a few more times and I am sure you will get it eventually. Cya!

Essential LINQ For Beginners 2 | WHERE

WHERE IN LINQ

Yesterday , we talk about how LINQ , using C# language , can select numbers the way SQL SELECT statement does. Today , we will go over examples of WHERE statement using LINQ. You can find the article showing LINQ with SELECT here. Hopefully after 2 or 3 more examples of LINQ statements , we can being to see the beauty of having the ability to interact with SQL Databases within the language directly. Lets take a look at the example then ,

LINQ Example

public void LinqWhere()
{
    int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

    var lowNums =
        from n in numbers
        where n < 5
        select n;

    Console.WriteLine("Numbers < 5:");
    foreach (var x in lowNums)
    {
        Console.WriteLine(x);
    }
}

As you might have guesses by simply reading the code , it take an array of integers , named numbers , from from that array , it selects those numbers less than 5 and pass it to another array. Then uses a “foreach” loop to prints out the list on each new line by itself.

You might ask what is this VAR type. It doesn’t seem to be an integer or String or anything we have seen before. Here is the definition of it from Microsoft website ,

“Beginning in Visual C# 3.0, variables that are declared at method scope can have an implicit type var. An implicitly typed local variable is strongly typed just as if you had declared the type yourself, but the compiler determines the type.”

It then gives two examples of using VAR and integer ,

var i = 10; // implicitly typed
int i = 10; //explicitly typed

Basically , instead of saying this is an integer , you let the compiler does the job for you. Both statements above are equal as far as your program is concerned.

LINQ WHERE Conclusion

Hope it helps someone who is struggling with LINQ and also hope you enjoy the read. Its been a great Sunday for me and cya tomorrow! There will be more LINQ!

Essential LINQ For Beginners

Essential LINQ

Alrighty , I shall now take a dive into LINQ from today onwards. SO what exactly is LINQ in the first place? This is one definition ,

LINQ (Language Integrated Query) is a Microsoft programming model and methodology that essentially adds formal query capabilities into Microsoft .NET-based programming languages. LINQ offers a compact, expressive, and intelligible syntax for manipulating data. The real value of LINQ comes from its ability to apply the same query to an SQL database, a DataSet, an array of objects in memory and to many other types of data as well. LINQ requires the presence of specific language extensions.

LINQ uses an SQL-like syntax to make query expressions well beyond the capabilities of embedded SQL as implemented in programming languages. That’s because embedded SQL uses a simplified, streamlined syntax to add SQL statements to other programming languages, where there’s no attempt to integrate such statements into the native syntax and typing mechanisms. Thus, you can’t invoke native language structures such as functions in embedded SQL statements, as you can using LINQ, because it is implemented to use native syntax, structures, and typing mechanisms. Furthermore, LINQ may be used to access all kinds of data, whereas embedded SQL is limited to addressing only databases that can handle SQL queries.”

Source Here.

LINQ Example

Well then what does it look like?

It looks like this ,

public void LinqExample()
{
    int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

    var numsPlusPlus =
        from n in numbers
        select n + 1;

    Console.WriteLine("Numbers++:");
    foreach (var i in numsPlusPlus)
    {
        Console.WriteLine(i);
    }
}

and this prints out ,

Numbers++:
6
5
2
4
10
9
7
8
3
1

If you remember or read the post on loops I did a while back , here is the link, you will notice that it looks very similar to the for loop we did back then , except that instead of going through numbers from start to finish , I went through a group or an array of lists.

An array is simply a container of objects such as an integers we have over here. One of the main usage is to have the group sliced and diced. You could for example , 5th place of an array or maximum values of the list. Of course , a table is also an array of data. You could select the maximum value in a specific column or choose a specific value. You could imagine here that there is a table with a column header named “numbers” and the values are entered as follow ,

Numbers
5
4
1
3
9
8
6
7
2
0

Then you would do a select all statement and then add 1 to the result. The result would be similar to above and that is one of the reason you would see such statements ,

var numsPlusPlus =
        from n in numbers
        select n + 1;

This in SQL would be

Select *  from numbers;

Hmms … I can’t seems to find a function that adds a value to the select output .. But you get the drift. This is where we will be starting out on LINQ and I hope to have more examples in future. Cya!