Book Review: Version Control With Git

Your first encounter with GIT as a version control tool may be quite intimidating, especially if all you had been using so far was something simpler like Subversion, TFS or, God forbid, Visual Source Safe. “Version Control with GIT” by Jon Loeliger, Matthew McCullough (published by O’Reilly) leads you on a journey to become a master of the tool. But the path is not short and easy. If you need quick gratification, then you might have to look elsewhere.

Version Control with GIT

Version Control with GIT

Do I Need a Book on GIT?

There a plenty of GIT related resources online, and more get added the more it is adopted even outside of the open source world. If your use of GIT is just only to share your own pet projects on GitHub or to occasionally fork an open source repository, make a few changes and submit a pull request, then probably a brief list of commands with some basic concepts will get you covered.

On the other hand, if to use GIT on a daily basis at work, or work on a complex open source project with dozens of contributors and hundreds of commits, then you need to go a bit deeper and understand the nuts and bolts.

What’s In The Book

After touching briefly on the installation process, the first dozen of chapters deal exclusively with one (local) repository: the object model, the index file, commits, branches, diffs and the all important concept of merging. Sometimes the description is so accurate that you can almost visualize the software data structures underlying the design concepts the author is guiding you through; but this is not just a technical curiosity to entertain the reader: everything that is discussed has got practical implications on your usage of the tool (e.g. which merge algorithm you should choose, or whether to opt for a ‘rebase’ versus a ‘cherry-pick’).

The book then devotes a couple of chapters covering how to interact with remote repositories, and then tackles more advanced topics like repository management,  patching, hooks, submodules, interacting with SVN and a few other tip and tricks. It finally mentions GitHub in the last chapter.

The Good and the Bad

If you need detailed information about GIT, then this is the deal (short of reading the source code I guess). Every aspect of the tool is explained (sometimes in excruciating detail) and the authors go to a great length to provide tips and gotchas on commands (especially when you might easily shoot yourself in the foot). However this is not a quick read and it will take time to digest it.

What’s missing, maybe, it’s a ‘quick start’ chapter at the beginning to get you going if you need to be up and running in a short amount of time (say you have landed a new job where GIT is in use and you have little or no experience). That would help with the transition while giving you more time to go through the details. Unfortunately, the reader will have to look for such a compendium elsewhere.

 

 

Posted in Reviews | Leave a comment

Firefox, Fiddler and HTTPS

Today I was debugging some interaction between one of our products and Twitter 1.1 API protected by OAuth 1.0a . As it happens, I was using Fiddler to have a look at tokens being passed back and forth.

As I finished my debug session, I forgot to turn off Fiddler session and wanted to check my emails on gmail. I was getting warnings by Firefox about google SSL certificate chain not being valid. Strange. Then I moved to Facebook and there I also had all kind of problems. After adding an exception for Facebook.com to the SSL trust (!) I was able to open the site, but as text only without any additional resource (images, css): you can imagine what Facebook site looked like. I could not even browse to support.mozilla.org because Firefox did not even trust that side (ironically enough…)!

After a white it dawned on my that Fiddler might be the culprit: surely enough, after turning off Fiddler everything went back to normal.

So the moral of the story is: if you see sudden problems with Firefox and HTTPS, be sure that you don’t have Fiddler running in the background causing havoc. :)

UPDATE: Eric in the comments suggests how to configure Firefox to accept Fiddler’s certificate (see http://fiddler2.com/blog/blog/2013/04/01/configuring-firefox-for-fiddler)

Posted in Misc, Tools | Tagged , , , | 2 Comments

Dependency Injection for Dummies

Antonio Vidal has translated this post into Spanish: you can find it here.

Dependency injection is a very simple concept: if you have an object that interacts with other objects the responsibility of finding a reference to those objects at run time is moved outside of the object itself.

What does it mean for an object to "interact" with other objects? Generally it means invoking methods or reading properties from those objects. So if we have a class A that invokes method Calculate on class B, we can say that A interacts with B.

In the following example we show class A interacting with class B. We can equally say that A depends on class B to fulfill a responsibility. In this case, it not only invokes its method Calculate but it also creates a new instance of that class.

class A
{
  private B _b;

  public A
  {
    _b = new B();
  }
   
  public int SomeMethod()
  {
    return (_b.Calculate() * 2);
  }
}

In the following example, on the other side, the responsibility of getting a reference to an implementation of a class of type B is moved outside of A:

class A
{
  private B _b;
  public A(B b) 
  {
    _b = b; 
  }
  public int SomeMethod()
  {
    return _(b.Calculate * 2);
  } 
}

In this case we say that a dependency (B) has been injected into A, via the constructor. Of course, you can also inject dependencies via a property (or even a regular method), like in the following example:

class A
{
  private B _b;

  public B B 
  { 
     get { return _b; }
     set { _b = value; }
  }

  public int SomeMethod()
  {
    if (_b != null)
        return _b.RetrieveValue() * 2;}
    else 
        // HANDLE THIS ERROR CASE
        return -1;
  } 
}

So this is all there is about dependency injection. Everything else just builds on this core concept.

Like for example Inversion Of Control (IoC) tools which helps you wiring together your objects at run time, injecting all dependencies as needed. So what exactly is Inversion of Control and how does it relate to Dependency Injection (DI)?

I like to associate IoC to the Hollywood Principle: "Don't call us, we'll call you". IoC is a design principle where reusable generic code controls the execution of problem-specific code: it is a characteristic of many frameworks, where the application is built extending or customizing a common skeleton; you put your own classes at specific points and the framework will call you when needed.

You can use an IoC container as a framework to perform Dependency Injection on your behalf: you tell the container which are the concrete implementation classes for your dependencies and the container will make sure that your constructors or setters will be called with the right objects.

Therefore, IoC containers are just a convenience to simplify how dependency injection is handled. But even if you don't use one you could still manually perform dependency injection.

(If you want to have a look at how an IoC container works you can jump to my mini tutorial on Ninject).

Why is the concept of dependency injection important? Because by applying it, you simplify your design (separating the responsibility of using an object from the responsibility of retrieving that object) and your code becomes much easier to test, since you can mock out the dependencies substituting them with fake (stub) objects. But that is the subject for another post.

Posted in .NET, C#, Design and Patterns | Tagged , , , | 7 Comments