Something else we touched on in “Being a Better Developer” are the benefits of deliberate practice.
Over the years I’ve developed a habit I’d consider deliberate practice, and that’s the habit of writing unit tests when learning a new language, framework, or library. I’m not testing for quality, but trying to internalize what I’m learning about a new topic by writing code and experimenting.
Learning becomes a combination of reading documentation, reading source code (sometimes via a decompiler), and practicing code by writing code in tests.
For example, here are some of the tests I’ve written again the new Immutable Collections:
[Fact] public void Modification_Returns_A_New_List() { var list1 = ImmutableList.Create<int>(1); var list2 = list1.Add(2); Assert.False(Object.ReferenceEquals(list1, list2)); } [Fact] public void Create_Always_Returns_Same_Empty_List() { var list1 = ImmutableList.Create<int>(); var list2 = ImmutableList.Create<int>(); Assert.True(Object.ReferenceEquals(list1, list2)); } [Fact] public void Clear_Returns_Same_Empty_List_As_Create() { var list1 = ImmutableList.Create<int>(1,2,3); var list2 = ImmutableList.Create<int>(); list1 = list1.Clear(); Assert.True(Object.ReferenceEquals(list1, list2)); }
Writing simple tests like these give me confidence in using a new technology.