How do you get to be better at coding? You could read more, go to conferences, take some online classes, .... but ultimately it comes down to mindful practicing.
Practice you say, what about just doing our jobs?!? Yes, that is important but do you really want to try something new and crazy with your source of livelihood?
That is were Code Katas come into play. The idea with a Code Kata is work on a simple coding problem so that you can focus on how you are solving it.
Always wanted to try BDD? Try it in a FizzBuzz kata.
Want to try out functional programming? Use it on the Coin Changer kata.
3. – Micah Martin
“Katas can stretch our abilities and,
similar to how a kata would teach a
martial artist to become comfortable
with the uncomfortable, they help us
write code we may not normally
write.”
12. Coin Changer
Given coins of different values
Find the number of coins given back
for a given amount
13. using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CoinChanger
{
public class Changer
{
public ICollection<int> Coins { get; set; }
public Changer()
{
Coins = new List<int>();
}
public ICollection<int> For(int amount)
{
return Coins.Aggregate(
new State(new List<int>(), amount), (working, coin) =>
{
working.Result.Add(working.Amount/coin);
return new State(working.Result, working.Amount%coin);
}).Result;
}
class State
{
public ICollection<int> Result { get; set; }
public int Amount { get; set; }
public State(ICollection<int> result, int amount)
{
Result = result;
Amount = amount;
}
}
}
}
14. public ICollection<int> For(int amount)
{
return Coins.Aggregate(
new State(new List<int>(), amount), (working, coin) =>
{
working.Result.Add(working.Amount/coin);
return new State(
working.Result, working.Amount%coin);
}).Result;
}
15. class State
{
public ICollection<int> Result { get; set; }
public int Amount { get; set; }
public State(ICollection<int> result, int amount)
{
Result = result;
Amount = amount;
}
}