Tuesday, 3 June 2014

Learnings from software development coaching sessions

Back in November 2013 I wrote a post sharing with you my decision of being mentored by a friend and agile coach Matteo Baglini with the goal of exposing myself to agile engineering practises and become a better developer.

At the time, I promised to write posts about my learning but ultimately I didn't. So, it is time to start now!

First of all, I wish to thanks my manager Dom Smith in Red Gate Software to offer me the opportunity to have these sessions during working hours. This really offers me the ability to have sessions regularly every week.

In this post I will condensate the learning of the last few months of mentoring with links to the various resources that I read since then.

We started discussing TDD and the approach described by Kent beck:
  1. Write new code only if an automated test has failed
  2. Remove duplications
Duplication is the most important code smell and it can be hard to see. For this reason, sometimes it is useful to write verbose code just to help you find duplications.

I did the full Money example in the book TDD By Example exactly how Kent did it (with few changes as I did in C#) and deeply reflected on each step. I spent a full day to do it but it was worth the effort.

Learning well a refactoring tool like ReSharper is very important. However it is important to consider that the biggest advantages of a refactoring tool is not merely productivity:
  • Avoid the human error
  • Remove the context switch between using keyboard and mouse
  • Shorten the feedback loop by decreasing the time needed to refactor a piece of code
  • You can answer quickly questions like: Is the new design better?
Doing a kata multiple times without changing the solution to just focus in how you code and use refactoring tools is a very useful technique.

Here is a collection of very useful advices:

  • Check the error message when a test fail
  • Run tests often
  • After a refactoring run the tests
  • Avoid copy & paste as much as possible
  • When you find something to do, don't stop your current task. Add a note and do it later.
  • Don't stop the flow only to rename a method or a property! Add a note and do it later.
  • Primitive obsession can be often removed by introducing Value Objects
  • Sometimes you can add a test and comment it out in order to do necessary refactoring
  • Don't be too confident! Always use tests to validate what you are doing
  • Keep tests as stupid as possible. Limit test logic as much as possible!
  • In case of regression (red bar) never change test logic otherwise you won't know what was right
  • If you lose control, just slow down or discard changes and restart
  • Don't restrict yourself in a Top Down or Button up approach.
  • The code guides you. TDD is a feedback tool.
  • Consider adding code even if it is not strictly required to improve readability or simply to add symmetry
  • Some tests are simply tests to support you during development. You can remove them when other tests cover the same functionalities. Don't be afraid. 
  • Consider the "Copy Type" ReSharper command
  • The production code tests the tests!
  • Extract Method is a powerful refactoring tool
  • It is sometimes useful to make a private internal method public just for the sake of temporary writing unit tests but don't submit that code! Use it only to increase your knowledge about the problem.
  • Learn how to do small steps when needed.
  • A test is done only when duplication is eliminated!
  • Consider writing a test to force the creation of an object that we expect to need late but attention of not doing upfront design
  • Relying on the compiler can be a useful technique
  • If it takes a lot of time to make a test green... reflect!
  • Prefer static methods to factory classes when implementing the factory pattern
  • Getters are smells. Pay attention to not use objects as mere data structure.
  • Resist the temptation of not creating new classes... try, get feedback and see!
  • Observe the frequency of change. Change should be distributed among classes.
  • Use the Single Responsibility Principle to see pattern of change
  • The class who own the data should do the operation: Tell, Don't Ask!
  • In designing API it is best to offer a single way to do something. Make it simple!
  • Use the history in SCM to get insight about your project
  • Analyse temporal correlation of class changes
  • If you feel that something is annoying in the code base that is a sign of poor design.
  • Remain at the same level of abstraction within a test
  • Write a high level test and when you see the need to cover a lot of cases go down of one level of abstraction and write more specific unit tests.
  • You will often be pushing tests up and down between different levels of abstraction
  • Remember to not look inside the object when you do testing even on individual classes! Test the behaviour so that you can easily change the instance of the class with a new class but keep the tests intact.
  • Do not use TDD as a way to get permissions to write production code (that is cheating).
  • Do not be too enthusiastic about new technologies or methodologies. Slow down and reflect. There will be always a hype and later a fall. If you are pragmatic you can fall less.
  • Consider writing the assertion first

The essence of object orientation is thinking about behaviours

TDD test are always behavioural and at different level of abstraction. TDD can be done at different levels of zoom: it is sort of a dance between them. Unfortunately TDD has been often misunderstood and even attempts were made to fix this with ATDD and BDD. But these methods have often been identified with tools and things like Cucumber only create a new layer without bringing much value: having the on-site customer is far better than executable requirements that are a dream.

Pair programming helps a lot to keep focused and the role of navigators is supporting drivers in maintaining discipline and avoiding distractions

I and my mentor discussed many times about the Theory of Constraints and the importance of identifying bottlenecks in order to remove them. It is quite interesting to note that also humans can be a bottleneck and therefore an issue that can be addressed by increasing sharing. This can be done both with pair programming or with the Expert in Earshot pattern.

Quotations:
I never known exactly how to achieve high cohesion and loose coupling regularly until I started writing isolated tests, Kent Beck
I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence (I suspect this level of confidence is high compared to industry standards, but that could just be hubris). If I don’t typically make a kind of mistake (like setting the wrong variables in a constructor), I don’t test for it. I do tend to make sense of test errors, so I’m extra careful when I have logic with complicated conditionals. When coding on a team, I modify my strategy to carefully test code that we, collectively, tend to get wrong. Different people will have different testing strategies based on this philosophy, but that seems reasonable to me given the immature state of understanding of how tests can best fit into the inner loop of coding. Ten or twenty years from now we’ll likely have a more universal theory of which tests to write, which tests not to write, and how to tell the difference. In the meantime, experimentation seems in order. Kent Beck
Resources:

Monday, 2 June 2014

Stored Procedure to Calculate Expressions

I was reading the section Character Functions in the Chapter 2 of the book Querying Microsoft SQL Server 2012 and pretty soon I get bored of trying individually the various functions on strings available in T-SQL.

Then, I challenged myself to write a stored procedure (this is my first one) to evaluate an arithmetic expression with parenthesis and show the individual steps of the calculation. I wanted something generic but I added some restrictions to it after seeing how crazy is to implement a split function in T-SQL.


This is the stored procedure. I know, it is crazy and I am sure there are much better way of doing it. Remember that my goal was to just get confidence with the T-SQL functions on strings. Anyway, I am happy to receive feedback on it and see different way of implementing this behaviour.


This is the result of the execution.


It was fun :)



Friday, 30 May 2014

My Personal Brand Survey Results (2014)

In the last few years, I read some books about personal branding and pretty much all of them highly recommend to take an anonymous 360 degrees surveys in order to understand how people perceive you.

For this reason, I decided to give it a go and try.

After a little bit of research I decided to use the 360 Reach platform. The survey is completely free for 15 days but I decided to pay for a premium version in order to get more results and a detailed report out of it.

In this post I am going to share with you the most interesting results.

Wednesday, 28 May 2014

Preparing for Querying Microsoft SQL Server 2012

Few months ago I joined Red Gate Software and I am having a lot of fun so far. We have a great team in SQL Compare and we are working hard to add support for SQL Server 2014.

I think that learning more about SQL Server is very important because a lot of Red Gate products are designed to make DBA and developers working with it in a very productive way.

This is why I decided to start the path toward becoming a MCSA on SQL Server. To be honest, as a developer, my goal is just learning more about SQL Server and not necessarily get certified. However I will use the certification materials as a clear path to increase my knowledge.

The first exam on the list is
[70-461] Querying Microsoft SQL Server 2012

I know SQL and I have studied database development and design at University. However I don't know much about SQL Server specific features and the incredible power that the platform can offer. 

In order to keep me motivated I will post on my blog all the things I found interesting during my learning.

The following is a list of all the resources I will use to prepare for this exam:

It's time to write SQL :)

Tuesday, 27 May 2014

Growing Object Oriented Software, Guided By Tests

Few weeks ago I finished to read the famous book
Growing Object-Oriented Software, Guided by Tests

In this post, I try to summarize what I think is the most interesting content.

The book present the interesting approach of starting a new project with a Walking Skeleton that is a tiny implementation of the system that performs a small end-to-end function
The point of the walking skeleton is to help us understand the requirements well enough to propose and validate a broad-brush system structure.
In most Agile projects, there’s a first stage where the team is doing initial analysis, setting up its physical and technical environments, and otherwise getting started. This is usually called Iteration Zero.


Friday, 23 May 2014

Top 10 Debugging Tips in Visual Studio 2013

I watched the "Debugging Tips and Tricks in Visual Studio 2013" session from TechEd and I found some very interesting debugging tips I was mainly unaware of.

Run to Cursor (CTRL + F10)

Run the debugger and stop in the location of your cursor. This allows you to debug your code from a particular location without the need to set a breakpoint. This is useful because often people create breakpoints but forget to remove them and the debugging becomes very slow.

F11 
You can start your application and automatically break at the first line of code. This avoid you to manually find the entry point of the application.

Sunday, 4 May 2014

Thank you BASIC!

The first of May 2014 was the 50th Birthday of BASIC.

I couldn't resist the temptation to write a post on it because BASIC has been my first programming language and I have used it for more than 9 years. Seriously? Yeah :)

Actually, I didn't write BASIC programs on a PC but on Casio calculators using a variant called Casio BASIC.

This was the power of my first programming language :)
Casio graphic calculators use a BASIC-like programming language but variable names are restricted to single letters A-Z which are shared by all programs including subroutines which are stored as separate programs. This means there are no local variables, they are all global. These variables are also shared by other functions of the calculator. For example, drawing a graph will overwrite the X and Y values.
Everyone who grow up with me knows that I never walked without my calculator in my pocket. I was a true geek :) Most of the time I used to create games for my friends: board games, card games, strategy games, casino games and so on. They were pretty popular!

The first 5 years I only coded on the Casio calculators. Then I got a PC and I also started to write code with Visual Basic and C/C++. However, I didn't have a laptop so I continued to write code on the calculator for other 4 years so that my friends could play on the train.

Saturday, 3 May 2014

Becoming an Outlier: Reprogramming the Developer Mind

I finished to watch an awesome course on Pluralsight from Cory House
This course is not intended for everyone but only for the people who really love their work and want to become the best they can be.

Cory created a website to lunch a movement of developers who don't want to be average!

The manifesto contains three simple statements:
  • I’m not interested in being average. I’m out to be exceptional. 
  • I’m not waiting to be picked. I’m actively creating opportunities. 
  • I’m commanding my time so I can own my trajectory and maximize my impact.
I really like the quotation he used to describe himself.
"If it’s work, we try to do less. If it’s art, we try to do more." - Seth Godin
Software is my art. 
He really inspired me. Are you?