Functional Programming Talk

Monday, May 20, 2013

Yesterday I had the pleasure of speaking in front of a number of my colleagues in Sela about functional programming.  My talk’s title was ‘The Essence of Functional Programming’ and it dealt with what I consider to be the primary differences between functional and other languages.  Thanks to everyone who came – it was pleasure (broken air-conditioning not withstanding..)!  Slide deck is available here.

Testing a Longest-Common Prefix Implementation Using Model-Based Testing

Wednesday, May 15, 2013

In  my last post I discussed how to implement a Longest-Common Prefix (LCP) algorithm in both an imperative and functional manner in C#.  I also mentioned the fact that for the imperative implementation I needed some to write some unit tests.  Here is the test code: public class LCPTests { public void Get_WithNoValues_ShouldReturnEmptyString() { string result = LCP.Get(new string {}); Assert.AreEqual(0, result.Length); } ...

Longest Common Prefix with C# and LINQ

Friday, May 10, 2013

I recently can across an interesting problem:  Given a set of n directories, find the most nested directory that is an ancestor of all of them.  This is equivalent to finding the longest common prefix. For example, if I have the following paths: /dir1/dir2/dir3 /dir1/dir2/dir4 Then the longest common prefix is just /dir1/dir2.  If we now add /dir1/dir5 to the set, we get: /dir1/dir2/dir3 /dir1/dir2/dir4 /dir1/dir5 Then the longest common prefix changes to /dir1.  In order to do this, I start by comparing the first and second directories by splitting them on the / symbol, and then comparing the elements of the resulting arrays. ...
one comment