Flawless Demos using Git

Premier Developer

Premier

In this post, Premier Consultant Andrew Charbonneau shares some tips for flawless demos using Git.


If you are anything like me, you are not a stranger to demoing some sort of code snippet in front of a live audience. All too frequently, this means actual live coding, and subsequently, typos and syntax errors. These small typos can sometimes take away from the point you are trying to teach, when you should be actively trying to keep everyone engaged and on topic. To combat these pesky errors and try to keep the room focused, I have started using git to help in these scenarios. Now, as soon as you hear the word ‘git’ your mind likely jumps to thoughts of code repositories, pull requests, and branching strategies. That would be a natural progression, especially considering how we use git in our daily lives. However, even Linus Torvalds, the creator of Linux kernel, and subsequently git, describes the version control system as ‘the stupid content tracker.’ It is precisely the content tracking and version control basis of git that can also be used to help provide flawless demos in front of colleagues or customers.

Recently, I was giving a presentation on Test Driven Development, TDD. If you are not familiar with this concept, a developer writes their own test case, prior to writing a single line of functional code. The test case will fail at first since there is no functional code. The developer must then write some code, and that will begin an iterative cycle of updating the functional code and then the test case code; until the code is working as expected, and the coded test case passes as well.

The example I was using during my demo was determining if a number was ‘Odd’ or ‘Even.’ The example included two projects, an OddEven.Library and an OddEven.Tests, each having only one class file, OddEvenService.cs and OddEvenTest.cs, respectively.

Rather than coding in front of everyone while talking through these steps, I had completed the setup in advance, and created different git branches to jump from step to step of the process, so that I could focus on explaining the theory, and what was happening, and not need to focus on my actual typing. To advance to the next step in the process, with updated class files, all that I needed is to do is checkout a branch in git. In VS Code, it is as easy as clicking the branch in the bottom left hand corner and choosing the next step.

Here are the branches and steps I used, and the results of the dotnet test. Please keep in mind this is not complex code, and the concept of using branches can be applied to nearly any code you are trying to demonstrate in steps or stages.

Master/Step 1 Branch – Test Fails

OddEvenService.cs – Returns Nothing

OddEvenTest.cs – Checks that it gets a value of 1 from the OddEven Service

Step 2 Branch – Test Passes

OddEvenService.cs – Returns a hard-coded value of 1

OddEvenTest.cs – Checks that it gets a value of 1 from the OddEven Service

Step 3 Branch – Test Fails

OddEvenService.cs – Returns a hard-coded value of 1

OddEvenTest.cs – Checks that it gets a string of ‘Odd’ or ‘Even’, from the OddEven Service

Step 4 Branch – Test Passes

OddEvenService.cs – Check if a number has a 0 remainder after being divided by 2. If yes, it passes ‘EVEN’, else it passes ‘ODD”

OddEvenTest.cs – Checks that it gets a string of ‘Odd’ or ‘Even’, from the OddEven Service

Using git branches allows you to quickly jump back and forth between branches, while the IDE updates instantly as soon as you checkout a branch. Use this to focus on the theory and give flawless demo’s in the future!

 

0 comments

Leave a comment