Ill

Being ill sucks

Last week I was really very ill – something flu-like – and this week I’m slowly recovering from whatever it was. Beside sapping all of my energy it’s also completely messed with my ability to actually think. Because of that, I haven’t really done anything particularly interesting – I’ve been using this time to do all of the boring / monotonous tasks that I’d been putting off – and haven’t had any particularly exciting insights into, well, anything really.

Never too ill for a monad

Since I’ve not really done much, and I’m not feeling up to writing about anything particularly involved, here’s a very simple error monad-like-structure I threw together this week for something I was working on.

public class Exceptional<TValue>
{
	#region Fields

	private readonly TValue value;
	private readonly Exception exception;
	private readonly bool hasResult;

	#endregion

	#region Constructors

	private Exceptional(TValue value)
	{
		this.value = value;
		hasResult = true;
	}

	private Exceptional(Exception exception)
	{
		this.exception = exception;
		hasResult = false;
	}

	#endregion
	
	#region Methods

	public Exceptional<T> Apply<T>(Func<TValue, T> func)
	{
		return UnWrap(
			v => Exceptional<T>.Wrap(() => func(v)),
			ex => new Exceptional<T>(ex));
	}

	public T UnWrap<T>(
		Func<TValue, T> whenResult,
		Func<Exception, T> whenException)
	{
		return hasResult
			? whenResult(value)
			: whenException(exception);
	}

	public static Exceptional<TValue> Wrap(Func<TValue> func)
	{
		try
		{
			return new Exceptional<TValue>(func());
		}
		catch (Exception exception)
		{
			return new Exceptional<TValue>(exception);
		}
	}

	#endregion
}

The brain is a muscle…

So, even though I really wasn’t feeling particularly up to it, I wrote something similar to the above in F#. I’m trying to slowly get a feel for the language after years of OOP indoctrination, and this is (sadly) probably the biggest thing I’ve written in F# so far. I love the concepts behind the language but it can be incredibly frustrating to move from being able to produce clean, concise, idiomatic code in C# to struggling to write even the simplest structures in F#.

type Exceptional<'a> = 
	| Value of 'a
	| Ex of Exception

// (a -> b) -> (a -> Exceptional<b>)
let Bind f = 
	fun a -> 
		try Value(f a) 
		with 
			| ex -> Ex(ex)

let incr x = 
	match x with 
		| 7 -> 	raise (Exception "Seven Eight Nine")
		| _ -> 	x + 1
		
let _incr =  Bind incr

_incr 3 |> Console.WriteLine
_incr 7 |> Console.WriteLine

Devlore

It’s the same old story…

Once again the top story on Hacker News was something I’ve read many times before – The 500-mile email – and I won’t lie, I read it again. There are a number of such stories, most developers who’ve been in the industry for some time undoubtedly know quite a few of them. Often about a hard-to-find bug or a laughably incompetent colleague or user, one thing that unites them all is that you can guarantee you’ll see them again; maybe not for a month, maybe not for a year, maybe in a slightly different retelling, but they’ll be back.

The first sentence of the Wikipedia article on lore says:

Folklore (or lore) consists of legends, music, oral history, proverbs, jokes, popular beliefs, fairy tales, stories, tall tales, and customs included in the traditions of a culture, subculture, or group.

Every item on that list applies to the developer community, from the myth of the 10x developer to musicforprogramming; from Falsehoods Programmers Believe About Names to Exploits of a Mom; we even have our own idiolect: Heisenbug, YAGNI, kludge; our own revered heroes: Donald Knuth, Marting Fowler, Kent Beck; our archetypal villains: business analysts, users, PHP.

There’s no real conclusion to be had here, I simply found it interesting to realise that we’re not just a group of people sharing a career, we’re an entire (sub)culture. How many other careers have this level of cultural identity? Is there something unique to development and developers that lends itself to this?

The recent StackOverflow Developer Survey suggests that:

Code is life for most devs, and for many coding is a lifetime pursuit.

Is coding more of a lifestyle than a career? Does our population being generally more introverted lead us to embrace shared experience more strongly? Or is it simply that our skills with – and constant use of – technology allow us to share more easily with each other?

Just a shower thought for the day, really…