Wednesday, 4 April 2012

What to focus on?

Today during the daily commute I was thinking about what technologies I should focus on. After thinking for a while I couldn't keep count of all things, so here it is in writing. :)

These are the areas I want to learn...but prioritization is needed otherwise I would end up learning nothing:

- WPF: In my day job most of the apps I develop are Windows (WPF) applications. So it makes sense for me to dig deeper into WPF. Going deeper into various MVVM frameworks is something I want to pursue.

- ASP.NET: We do have one BIG web application here. It's written nicely and architecture is quite cool. But it is still using WebForms approach, so I need get upto speed with ASP.NET MVC applications (also jQuery).

- .NET 4.0: Specifically parallel and async features - parallel LINQ, parallel task library, async/await. Dynamic feature.

- Unit Testing: especially Mocking tools

- Entity Framework: Although I am comfortable working with LinqToSql, EF is getting better with each new release. Need to get deeper into this (version 5.0 beta released last week.)

- Silverlight: No one is sure about its future, but in my view it is still a formidable option to consider in local-intranet scenarios

-  Performance / debugging: Go deeper into WinDbg, DebugDiag, performance issues (general and COM)

- iPhone/iPad dev using MonoTouch

- Windows 8 dev: Dip toes in the WinRT development using C# and build Metro applications (registered with a boot camp on May 10)

- Learn more about these concepts: Dependency inversion techniques, Test driven development, SOLID principle

- F#: In some scenarios F# fits very well. Need to at least have "intermediate" level of knowledge.

- Cloud computing, virtualization: This has gathered pace and it can longer be ignored as future of tech. This is in the 'now'. Plan to look into what other vendors offer. Application virtualization is also getting very interesting.

- Scripting: I like what I see in PowerShell, want to get started with it. Using it can be huge time saver in some scenarios.

- Kinect/XBox: Microsoft released Kinect for Windows SDK and the hardware will be launched in Singapore in June. Another exciting technology which can have a huge impact.

- Project management:  This is something big, but necessary. The target is not just to become a better programmer but a manager as well sometime in future.

- Architecture: TOGAF certification


Sunday, 1 April 2012

The cloud is here.

Just read an article about the jobs that will be eliminated because of companies moving to cloud. My initial guess before reading the article was correct - the IT infrastructure support ppl. like network admins, mail server maintenance would be affected first. In fact, the company where I consult recently migrated to Gmail from Outlook and I already see less calls being made to support guys.

So the support group will be affected first and then the "custom development" teams would be affected. Companies whose core function is not IT or where it is treated as a cost center would more readily use cloud.

So how does it affect Microsoft developers like us? We do not have many options. If we want to stick to Microsoft then the only option is to learn about Azure. But I think it is time for a MS developer to leave his comfort zone and start evaluating technologies from other vendors.

Once again 'change' is on horizon. I guess this is how C++/VB developers might have felt circa 2000 when world was changing with .NET release. .NET lasted for a decade and I suspect its time is up. With Windows 8 WinRT exposing its API to C#, bypassing .NET it is a hint of big changes to come. The tablet and mobile will perhaps kill .NET. .NET was built for PC and with PC fading away perhaps its time too has come to go.

I like the closing remarks of the article "Embrace the cloud, don't fight it".

Friday, 30 March 2012

Code snippets in Visual Studio

I must admit I was not a big user of snippets in programming. I used a few because they popped out in intellisense - for example while writing a for-each loop the snippet "foreach" comes up and we intuitively use it.

Never looked deeper to find other snippets. Today I realized I was at a big loss by not using them! Now I am never going to declare a property with all the key-strokes or writing if-else without using snippets. The no. of key strokes required are so less that it will improve developer's productivity by a good margin.

A few I like:
- mbox: If I use only this one it will save a lot of time for me.
- else: This one popped up in intelli sense but still didn't use it. 3 key strokes with snippet and 11 without
- prop: for automatically implemented properties
- ctor: for spitting out the constructor
- svm: for static void main

Other useful ones are 'surrounds with' snippets. Among these I like "try" which surrounds a code block with try-catch statement. What a time saver!

And another cool thing is we can add our snippets, it's just editing an XML file some where. I will see which ones are missing and add on my own. Should be fun.

(This reminds me there is so much still to learn and that even the smallest of things can be of BIG use)

Tuesday, 13 March 2012

Xsd2code

http://xsd2code.codeplex.com/

A tool which helps generate C# code from a XSD file. It can be very useful to generate classes which have a long list of properties - and you want to add WCF DataContract attributes, INotifyProperty code on these properties.

It also can be used when your application has lots of reference data. We can manually create XSD file with the reference data as enumeratio, then generate the class - and use this class in application. The class can be serialized and loaded back again if new items can be added by user.

There is also an option to auto-generate the classes if XSD file changes, I believe this requires installing a VS plug-in. The classes generated are partial classes, we can create another partial classes with same name if we want to add our own business rules.

#read: Code Generation in the .NET Framework Using XML Schema
http://msdn.microsoft.com/en-us/library/aa302301.aspx

Monday, 12 March 2012

Books (currently reading and to read)

Currently reading:
- Advanced MVVM
- LINQ in Action
- Pro LINQ
- WPF Unleashed

To read:
- Software Requirements:



- Pragmatic Programmer
http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X


- The Passionate Programmer: Creating a Remarkable Career in Software Development (Pragmatic Life)
http://www.amazon.com/The-Passionate-Programmer-Remarkable-Development/dp/1934356344/ref=pd_sim_b_6

- Code generation in .NET


- Refactoring: Improving the Design of Existing Code






Monday, 27 February 2012

Regular Expression in LINQ

string[] companies = { "microsoft", "IBM", "oracle", "google", "apple", "facebook", "RIM" };
//wildcard search to "%o%o%"
Regex regex = new Regex("oo");
var oo = companies.Where(c => Regex.IsMatch(c, "o.*o")).Select(c => c);
var oo1 = from c in companies
		  where (Regex.IsMatch(c, "o.*o"))
		  select c;
oo1.Write();


Here we are searching for company names containing two “o”, need not be consecutive.

How to use LIKE, IN - in LINQ

How do we use LIKE (from SQL) in LINQ?

One option:
-> use string.Contains() method

string[] companies = { "microsoft", "IBM", "oracle", "google", "apple", "facebook" };
//get companies which have 'oo' in them
IEnumerable<string> companiesWithAnO = (from c in companies
                 where c.Contains("oo")
                 select c).ToArray();


Also we can use string.StartsWith() and EndsWith().

-> Second option: This is only if we are using LINQ To SQL.

string[] companies = { "microsoft", "IBM", "oracle", "google", "apple", "facebook" };
//get companies which have 'oo' in them
IEnumerable<string> companiesWithAnO = from c in companies
             where SqlMethods.Like(c,"%oo%")
             select c;

The IN operator is also quite easy.

string orangeFruit = "orange";
string[] fruitBasket = {"apple","orange","mango","leechy" };
//check orange is in the fruit basket
bool orangeFound = fruitBasket.Contains(orangeFruit);

“Contains” is the extension method in the IEnumerable<T> class.

Sunday, 26 February 2012

LINQ: Differed Queries

LINQ queries, by default, are differed. It means that the original source collection is accessed only when the collection containing the LINQ output is enumerated. Let us see an example.
string[] companies = { "microsoft", "IBM", "oracle", "google", "apple", "facebook" };
//get companies which have 'oo' in them
IEnumerable<string> companiesWithAnO = from c in companies
           where c.Contains("oo")
           select c;
foreach (var item in companiesWithAnO)
{
 Console.WriteLine(item);
}


Output: google, facebook.

Let’s add a new line after the LINQ query.
try
{
 string[] companies = { "microsoft", "IBM", "oracle", "google", "apple", "facebook" };
 //get companies which have 'oo' in them
 IEnumerable<string> companiesWithAnO = from c in companies
       where c.Contains("oo")
       select c;
 //set IBM string to null
 companies[5] = null;
 foreach (var item in companiesWithAnO)
 {
  Console.WriteLine(item);
 }
}
catch (Exception ex)
{
 Console.WriteLine(ex.ToString());
}

O/P: Google, System.NullReferenceException…

So the first string “Google” is printed, but the next one gives error. Why? The reason is: when the LINQ query output variable – companiesWithAnO is enumerated, it accesses the original source collection – companies to get the results.

Let us check what the variable companiesWithAnO contains after the LINQ query but before the loop. Now we could check the companiesWithAnO.Count(), but this will give the output as 2, because running Count() will enumerate the collection – we need to prove that the collection companiesWithAnO hasn’t been enumerated and the original source not accessed yet.

We can try to have a look at the variable in debug mode, a breakpoint is set before the foreach loop.

image
The ‘Results View’ is not shown as it not yet enumerated. We change the query and add a ToArray().
IEnumerable<string> companiesWithAnO = (from c in companies
     where c.Contains("oo")
     select c).ToArray();

image

So the collection companiesWithAnO contains the values in this case.

Well we know now that LINQ queries are differed queries, except when we use ToArray() or ToList() or ToLookUp(). But why? We shall try that in next post.

Tuesday, 21 February 2012

LINQ: Extension Methods for Console apps

When designing Console apps for Windows, we usually write a lot of message to the console. It is a pain to write “Console.WriteLine(“xxxxxx”)” every time.

So let’s use extension methods to ease the pain.

Step 1> Create a Library project, add a class:

namespace LINQ.ExtensionMethods
{
    public static class MExtensions
    {
        public static void Write(this string s)
        {
            Console.WriteLine(s);
        }
    }
}


Step 2> Create a Console project, in the Main method:

        static void Main(string[] args)
        {
            "Welcome to Console project".Write();
        }


image



Let’s do this for a collection, no more writing loops or calling a method to iterate. Here we write an extension method for IEnumerable<T> in the class MExtensions above.

  public static void Write<T>(this IEnumerable<T> c)
        {
            Console.WriteLine();
            foreach (var item in c)
            {
                Console.WriteLine(item);
            }
        }

And to call:

    string[] games = { "Soccer", "Football", "Rugby" };
    var items = games.Select(p => new { p, p.Length });
    items.Write();

image

How to check when a machine was restarted?

Yesterday evening one of our test servers automatically rebooted. And today morning we found out that the last night’s test run was interrupted. Checking the logs and stuff, found out this was the case. So took on the task to find out what happened.

The best friend is Windows Event Logs – it is a reliable source to check computer’s history. (What happens in case of hibernate? #to-find)

Shutdown or reboot could happen because of various reasons and for each reason we could get a different Event ID. So we need is a quick way to find out the boot time . There are few events we can trust, the events logged by Event Logging service – that it is starting or shutting down. Very rarely would some one disable this service or start/stop it. The logs logged by Event Log Service are:

6005: logged at boot time, when the service starts
6006: at shutdown, that the service is stopping

The Date/Time of entries with these IDs can be taken as a rough idea when the computer stopped and booted.

In our case, we found that half an hour before a shutdown log – there was a log event (Event ID = 22, Category = Installation, Source = Windows Update Agent) logged by Windows Update – saying that the computer will be rebooted within 30 minutes.

More info: http://support.microsoft.com/kb/196452

Shorts - week 3, 2022

Post with links to what I am reading: 1. A very good post on different aspects of system architecture: https://lethain.com/introduction-to-a...