Know Thy Option

Avoid .get at all costs. Forget there is even a .get function on Option. There is always a way out - better one, than using .get. Same applies to .head

If you are going to have access the value in an Option in a test class, prefer extending your test class from OptionValues. Then you can use .value on an Option. Doing so establishes the presence of value as verification with meaningful error if value is not defined.

Pattern for Saner Mocking

It is common to see mocks being setup this way in unit tests.

scenario("Test Case 1") {
	...
	when(addressResolutionService.resolve(...)).thenReturn(...)
	when(vendorInventoryService.checkInventory(...)).thenReturn(...)
	...
	.... another bunch of when and then returns
	when(shipmentService.schedule(...)).thenReturn(...)

	...thisIsTheActualCalltoTest(...)

	verify(vendorInventoryService, 1).checkInventory(...)
	... other such verifications
}

scenario("Test Case 2") {
	...
	when(addressResolutionService.resolve(...)).thenReturn(...)
	when(vendorInventoryService.checkInventory(...)).thenReturn(...)
	...
	.... another bunch of when and then returns ...give or take one or more mocks compared to the previous test ...
	when(shipmentService.schedule(...)).thenReturn(...)

	...thisIsTheActualCalltoTest(...)

	verify(vendorInventoryService, 1).checkInventory(...)
	... other such verifications
}

... other such test cases

Cyrilex – Online Regex Tester

A while ago, I wrote the online regex tools. Cyril (@CyrilBois) came across that post and mentioned about his regex tester tool.

I think every tool should have a name; not one that just goes by its function but a nickname, if you will. So, I am going to name Cyril’s regex tool - Cyrilex. Don’t like it, don’t worry about it.

Instead of adding Cyrilex to the list, which I have already, I took the liberty to sort of review the tool. Because it has got a few cool things that I love.

Go away node/npm

If you haven’t found a use for this script that uninstalls the second largest junk in the world next to Mac/iOS updates, you are either lazy or scared of breaking things. I am neither, so I polished this script from the different versions you will find on the internet. Oh, I am talking about node/npm.

Happy cleaning!

A Rambling on Error Handling

In the early years, software applications were tiny, compared to what we build today. In any given application, one could say, there were only a handful of error scenarios to deal with. Besides, error reporting, if not error handling, lacked finesse. Just slap the user with something red enough, and just say An error occurred.

Facets of Immutability

Immutability, the cornerstone of functional programming, has many facets.

Not every (mainstream) language supports all the facets; at least not per what each facet stands for. That’s what I will talk about today. The various facets of immutability from a theoretical perspective, and briefly show how some of the mainstream languages have adopted and support these facets in their own way.

A Paradox of Braces

A great deal of thought goes into language design. Eric Lippert’s posts is a living testament, at least for C#.