Mohammed Omar's Blog

Just another WordPress.com site

What is New in Visual Studio 2013 – Git Support!

Introduction to Version Control Models

In Source control Models we have two main Models – Centralized and Distributed – version controls, both have different advantages and disadvantages, lets quickly get through both models to get to know each one in a deeper details.

Centralized Version Control Model

Centralized VC is based on the idea that we have only one repository (Copy of your Project) centralized in one computer which take the role of a server with multiple clients which connect to it to download a working copy of files making changes to it and then upload it back to the server after resolving conflicts if it occurred.

image

one of the things that characterize CVCM is the fact that the server will always have an idea if someone is working on a specific file or not, as you have to let the server know you are going to work on a file (Checking-Out) and also let the server know you are going to commit changes back to the server(Checking-In), this results for following advantages

Advantages
  1. The ability to monitor each and every file in your project at any time, get information like who is working on it, who is the last person who changed it.
  2. Since clients has to request working on a file, you can set several permissions levels on each and every file.
  3. Since we only have one Repository, it means CVCM works best for large scaled projects with millions of files
Disadvantages

However think about enterprise projects with multiple geographical teams working on different modules of the projects, this would mean every developer will have to have connection to the server every time he needs to check-out, check-in a file, which result on heavy load over network not to mention relying on the internet.

What about if you have made a work around over a bug or feature and want to save a copy of it locally ?!

Distributed Version Control Model

image

In distributed version control model whenever a developer clone server repository it means he gets a whole local copy of the repository to his machine, where he can now checkout files from local repository edit it and then commit it to his local repository and then push or pull to the remote server later when needed.

but what this gives us ?

Advantages
  1. Best offline experience ever!, you can even branch, merge locally without having to communicate to the server.
  2. No rely on connections or internet, which allows developer to be more productive when not connected to a network
  3. If the server failed any other local repository is a complete back up to the server with history of changes, logs etc.,
Disadvantages
  1. Initial cloning of the server repository can be slow as the client has to copy the whole repository with history, logs and everything to his local computer.
  2. Unlike CVCM, monitoring which files are being edited or who is working on which files can be hard.

CVCM vs. DVCMManual gear shift

Remember the flame war we used to have every time we discuss which gearbox is better than the other?

Manual(Standard) or Automatic Gearbox, its exactly the same when talking about Centralized verses Distributed, both has its advantages and disadvantages.

Team Foundation Server 2012 or Less

In previous version of Team Foundation Server we had CVCM, that what we loved and used, it allowed one Centralized repository, and worked great for large scale projects,

In Team Foundation Server 2012 Microsoft introduced Local Work-Space as an attempt to overcome CVCM disadvantage of not allowing working offline easily, by providing a way to work offline and enabling developer to edit, delete or rename files and delay informing the server of these changes until they get online, where server would discover pending changes and allow developer to resolve conflicts  and then safely commit his change-sets,

Local Work-Space allowed CVCM to have Edit-Commit model which allows developers to work offline, however CVCM couldn’t beat DVCM on providing the best offline experience. and on the other hand DVCM cant beat CVCM for providing best experience working with large scale projects.

So developer has to only pick one option and fight for it CVCM or DVCM just as drivers had to choose one options Standard or Automatic Gearbox,

Lucky drivers cars manufactures came up with a new gearbox which combine the advantages of the Standard and Automatic Gearbox ! and its called Steptronic !

And this is exactly what happened with Team Foundation Server 2013 !

Team Foundation Server 2013 and Git Support!

Microsoft wanted to combine the advantages of CVCM and DVCM, and give the developer the option to not only choose which Version control model he want to work with but can also combine both (Using Git-TF) !

In Visual Studio 2013 Microsoft introduce full support for Git Repository.

Picking up between TFVC and Git

image

Creating New Team project

image

Team foundation server 2013 can host fully fledged Git Repository, which you can use any native Git Client to connect to it and work with it just as you do with regular Git Server like Git-Hub

As you can see you can still use the same process template to Git Team project not to mention the same tools you used and love inside Team foundation Server 2013 and Visual Studio 2013!

Visual Studio 2013 IDE and Git Support!

Visual Studio 2013 IDE can now be used to connect to any Git Server and act as native Git Client!

image

image

Git-TF

Using TFS2013 you can even have one enterprise Project with two teams working on different Version Control model!

So let’s look at a high level overview over the underlying architecture of VS2013/TFS2013 to see what we can offer at the moment to our Enterprise customers and community

image

Project 1 use Team Foundation Server VC (Centralized Source Control Model) while Project 2 uses Git (Distributed Version Control) both has no awareness if the other team is using different model,  as Git-TF can be used to Sync between both repositories!

every and each developer is free to use the IDE he likes! and the platform he likes !, think of how this will help with projects with different teams background and different platform!

It Doesn’t matter if you are a java developer on Windows or on Mac or an IoS developer you can use the IDE you like and used to and be part of an enterprise geographical project using Team Foundation Server 2013!

[Arabic] Branching and Merging Visualization with TFS2012

In this lab you will be introduced to the branching and merging visualization support in TFS2012. This support makes it much easier to understand a solution branch hierarchy and to propagate changes during the merge process.

[Arabic] Unit Testing and Code Clone Analysis with VS2012

In this lab, you will learn how unit testing is being completely revamped in Visual Studio 2012. By making the unit testing engine in Visual Studio extensible, Visual Studio 2012 will open the door for 3rd party unit testing adapters such as NUnit and xUnit.net. You will also learn about how the new code clone capability goes hand-in-hand with delivering high quality software by helping you identify blocks of semantically similar code which may be candidates for common bug fixes or refactoring.

Unit Testing and Code Clone Analysis with VS2012 by Mohammed Omar

In this lab, you will learn how unit testing is being completely revamped in VS2012. By making the unit testing engine in VS extensible, VS2012 will open the door for 3rd party unit testing adapters such as NUnit and xUnit.net.

And We Are Celebrating Visual Studio 2012 Launch Too!

Hands-On Visual Studio

Its pleasure to announce the HandsOn Visual Studio,… Visit HandsOnVisualStudio.com to experience, learn & practice Visual Studio 2012 via guided, multi-lingual and real-life labs! !

  • Define
  1. Building the Right Software – Generating Storyboards and Collecting Stakeholder Feedback with VS2012
  • Develop
  1. Agile Project Management in Visual Studio Team Foundation Server 2012
  2. Using the Architecture Explorer in Visual Studio Ultimate 2012 to Analyze Your Code
  3. Understanding Class Coupling with Visual Studio Ultimate 2012
  4. Code Discovery using the Architecture Tools in Visual Studio Ultimate 2012
  5. Making Developers More Productive with Visual Studio Team Foundation Server 2012
  6. Branching and Merging Visualization with Visual Studio Team Foundation Server 2012
  7. Unit Testing and Code Clone Analysis with Visual Studio 2012
  8. Using Code Analysis with Visual Studio 2012 to Improve Code Quality
  9. Introduction to PreEmptive Analytics
  10. Debugging with IntelliTrace using Visual Studio Ultimate 2012
  11. Introduction to Test Planning with Microsoft Test Manager 2012
  12. Introduction to Test Case Management with Microsoft Test Manager 2012
  13. Authoring and Running Manual Tests using Microsoft Test Manager 2012
  14. Introduction to Platform Testing with Microsoft Test Manager 2012
  15. Introduction to Coded UI Tests with Visual Studio Ultimate 2012
  16. Exploratory Testing and Other Enhancements in Microsoft Test Manager 2012
  17. Introduction to Web Performance and Load Testing with Visual Studio Ultimate 2012
  • Operate
  1. Diagnosing Issues in Production with IntelliTrace and VS2012
  2. Lab Management Improvements in VS2012

Branching and Merging Visualization with Visual Studio TFS2012 By Mohammed Omar

Get introduced to the branching and merging visualization support in TFS2012. This support makes it much easier to understand a solution branch hierarchy and to propagate changes during the merge process.

Agile Project Management In TFS2012 By Mohammed Omar

In this lab, you’ll learn how TFS2012 can help you quickly plan, manage, and track work across your entire team. You’ll explore the new product backlog, sprint backlog, and task boards which can be used to track the flow of work during the course of an iteration.

Why the Yield return is Important!

You should always use yield when possible specially between layers, actually if it wasn’t for yield many features would be really hard to implement nowadays and to hear you say you don’t use it makes me wonder how you implement those features. Any way lets analysis some code:

Consider the following piece of code:

          public IEnumerable<int> Dolist()
        {
            List<int> nums = new List<int>();
            for (int i = 0; i < 5; i++)
            {
                nums.Add(i);
            }

            return nums;
        }

Looks so simple and straight forward isn’t it? We iterate over 5 digits add them to a list and return them…
So straight forward… now compile your code to dll and then disassemble it then check how the compiler compiled your code:

public class Class1
{
    // Methods
    public IEnumerable<int> Dolist()
    {
        List<int> nums = new List<int>();
        for (int i = 0; i < 5; i++)
        {
            nums.Add(i);
        }
        return nums;
    }
}

Nothing strange here everything is as expected…

Now try this code :

public IEnumerable<int> DoEnum()
        {
            for (int i = 0; i < 5; i++)
            {
                yield return i;
            }
        }

Now check the Compiled code:

public class Class1
{
    // Methods
    public IEnumerable<int> DoEnum()
    {
        <DoEnum>d__0 d__ = new <DoEnum>d__0(-2);
        d__.<>4__this = this;
        return d__;
    }

    // Nested Types
    [CompilerGenerated]
    private sealed class <DoEnum>d__0 : IEnumerable<int>, IEnumerable, IEnumerator<int>, IEnumerator, IDisposable
    {
        // Fields
        private int <>1__state;
        private int <>2__current;
        public Class1 <>4__this;
        private int <>l__initialThreadId;
        public int <i>5__1;

        // Methods
        [DebuggerHidden]
        public <DoEnum>d__0(int <>1__state)
        {
            this.<>1__state = <>1__state;
            this.<>l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
        }

        private bool MoveNext()
        {
            switch (this.<>1__state)
            {
                case 0:
                    this.<>1__state = -1;
                    this.<i>5__1 = 0;
                    while (this.<i>5__1 < 5)
                    {
                        this.<>2__current = this.<i>5__1;
                        this.<>1__state = 1;
                        return true;
                    Label_0046:
                        this.<>1__state = -1;
                        this.<i>5__1++;
                    }
                    break;

                case 1:
                    goto Label_0046;
            }
            return false;
        }

        [DebuggerHidden]
        IEnumerator<int> IEnumerable<int>.GetEnumerator()
        {
            if ((Thread.CurrentThread.ManagedThreadId == this.<>l__initialThreadId) && (this.<>1__state == -2))
            {
                this.<>1__state = 0;
                return this;
            }
            Class1.<DoEnum>d__0 d__ = new Class1.<DoEnum>d__0(0);
            d__.<>4__this = this.<>4__this;
            return d__;
        }

        [DebuggerHidden]
        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.System.Collections.Generic.IEnumerable<System.Int32>.GetEnumerator();
        }

        [DebuggerHidden]
        void IEnumerator.Reset()
        {
            throw new NotSupportedException();
        }

        void IDisposable.Dispose()
        {
        }

        // Properties
        int IEnumerator<int>.Current
        {
            [DebuggerHidden]
            get
            {
                return this.<>2__current;
            }
        }

        object IEnumerator.Current
        {
            [DebuggerHidden]
            get
            {
                return this.<>2__current;
            }
        }
    }
}

WHAT!????? So it’s not that you just don’t want to declare a variable to hold numbs! What is it then?

As you can see the .Net compiler would take your Code and compile it to a helper class which serve a State nested Class, to hold the state of every time you retrieve an item of the enumerator, which in other word you don’t get all the items at once! , it LAZY retrieve the items when you for each them which is perfect for LINQ! (isn’t that what LINQ is about?), so what! what advantage that would give me ?

Performance

Try the same implementation with 100 million numbers you will be amazed on the performance you get with a simple keyword (Yield), but guess what this is not all !

Yield return is one of the many keywords that Microsoft put into C# to support LINQ, part of the fact that LINQ is Lazy, let me put this into real example here and show you what you would gain from the Yield return keyword:

Consider this code:

public static class CustomerRepository
    {
        public static IEnumerable<Customer> GetAllNotLazy()
        {
            List<Customer> customers = new List<Customer>();

            for (int i = 0; i < 10; i++)
            {
                customers.Add(new Customer()
                                  {
                                      FirstName = "Mohammed",
                                      LastName = "Umar"
                                  });
            }
            return customers;
        }
        public static IEnumerable<Customer> GetAllLazy()
        {
            for (int i = 0; i < 10; i++)
            {
                yield return new Customer()
                    {
                        FirstName = "Mohammed",
                        LastName = "Umar"
                    };
            }
        }
    }

Now consider you`re in another layer or something with this code:

public static void Main()
        {
            var NotLazy = CustomerRepository.GetAllNotLazy().Where(x =>x.FirstName == "Mohammed");
            var Lazy = CustomerRepository.GetAllLazy().Where(x => x.FirstName == "Mohammed");
            foreach (var customer in Lazy)
            {
                //do stuff
            }
            foreach (var customer in NotLazy)
            {
                //do stuff
            }
        }

With GetAllNoLazy all your objects would be retrieved at once!
With GetAllLazy your objects would be retrieved once you need them!

Imagine you were checking something or applying some filter while your iterating inside the for-each and you decided to break! With lazy you wouldn’t lose much, without being lazy all your objects would be in memory anyway despite the fact that you break or not!

I can go on and on with situation where not using “Yield Return” would be a crime!

But I can sure now you can realize how the yield return was mandatory for LINQ and what situation you must use it otherwise implement your own State-Class…

Evolution Of Delegates Part 2

     So i assume you have read Evolution Of Delegates Part 1, any way lets start off by explaining anonymous delegate   

Anonymous Delegates   

     Anonymous delegates the ability to declare a delegate and the method it points to inline without the need to declare the method separately, well that sound awesome but sure it has  its advantages and disadvantages, like one of the disadvantages is you can not reuse that method in other places any way im sure you can come up with some other disadvantages ;)… so lets jump to how do we implement anonymous delegates?   

Consider this delegate:   

public delegate void MyDelegate(int left, int right);

And this method:   

        public static void sum(int left, int right)
        {
            Console.WriteLine(left + right);
        }

Usually we register it this method with that delegate like that   

      MyDelegate del = new MyDelegate(sum);
      //or using Method group conversion
      del += sum;

Now we want to register same implementation of  this method to that delegate without declaring the method how do we do that ? simple 3 steps:   

1-first copy the whole method and assign it to the delegate object:     

      mydelegate del = public void Sum(int left, int right)
			           {
				             Console.WriteLine(left + right);
			           }; 

2- Delete the method scope and return:

      mydelegate del = Sum(int left, int right)
			     {
				        Console.WriteLine(left + right);
			     }; 

3-Replace the method name with the keyword “delegate”:  

      mydelegate del = delegate(int left, int right)
                         {
                              Console.WriteLine(left + right);
                         }; 

guess what ! you made it now your project can compile no problem !, but wait ! there are some rules you have to know about anonymos delegates:

  1. Anonymous delegate can not access Ref/Out parameters in its defining method.
  2. Anonymous delegate cant declare a variable with the same name as a variable in its defining method.
  3. Anonymous delegate can declare a variable with the same name as member in its class but that gonna hide the outer variable.
  4. prolly there are some more im missing !.

any way in the next post im gonna be talking shortly about the Yield keyword and then we are gonna make a sample which mix all the previous features of C# then come up with how lambda expression and linq came out of all this ! thanks and see you later in the next post….

Evolution Of Delegates Part 1

What is delegate any way ?

             remember the topic called pointer to function in C/C++ you used to hate ? well its back again !, but this time Microsoft made a good job maknig this easier and more safe and secure.
             back in dark ages function pointers used to be defined as variable which points to address of a function, part of the fact that in C/C++ you had to manage memory your self it was kind of dangrous when you work with pointers in general, any way that is all changed in .net , now Delegates (reference to functions) are defined as

Type safe object which points to an execution of a method

            so how you define a delegate to point to a method ?

 consider this method:

        public static void sum(int left, int right)
        {
            Console.WriteLine(left + right);
        }

      in order to define a delegate which points to this function you do this steps :

  1. Clear Method Implementation.
  2. Clear static keyword.
  3. add the keyword “delegate” after method scope “public”.
  4. Add ; at the end.
  5. change sum to delegate name, (i will call it mydelegate).
public delegate void MyDelegate(int left, int right);

     Congratulation you just declared your first delegate!, any way you have to remember that to define a delegate you have to provide 3 piece of information of the method the delegate will point to:

  1. return type “in this example its void”.
  2. delegate name “Mydelegate”.
  3. Parameters “(int left, int right)”.

     Now what really happened behind the scene when you did that ?

By declaring Mydelegate you just defined a delegate class type which inherits from “System.MultiCastDelegate”, which in turns provide you with the ability to register multi methods to your delegate and provide you with a list of all the methods registered to your delegate!, in order to register a method to your delegate you have to create an object of your delegate and pass method name as a parameter to the constructor:

      MyDelegate del = new MyDelegate(sum);

Now to call the method by referencing the delegate you do the following:

      del(2, 3);

now if you want to register one more methods lets say this method:

 public static void Multiplay(int left, int right)
        {
            Console.WriteLine(left * right);
        }

You register it as following:

 del += Multiplay;

Notice here we used a feature called Method Group Conversion which allow you to assign a method directly to a delegate for registering it. I would like to stress something in here which is when you register a Method to a delegate you actually registering the execution of that method, that way if you registered a method 3 times that means the execution of that methods is going to happen 3 times, this is because every time your register a methods by assigning it using the operator += you actually call a IL method which is Combine which combine the method IL to the IL this delegate is pointing to!

To Be Continued….

Follow

Get every new post delivered to your Inbox.

Join 258 other followers