RSSAmplifier

Blog

devjoy

Recent content on devjoy

devjoy.comRSS feed ↗42 posts

Latest posts

Creating a Cron Job

I don’t create cron jobs very often. I do it rarely enough that I have to go figure it out each time. Tonight I needed to create a cron job on my home server. Rather than look it up again, I told Claude to do it for me. Tasks like this are exactly the kind of thing that many devs will happily offload to AI. 
 Whether we actually create cron jobs by hand or not, we will still need them. I…

Testing Async Code in C#: What's Changed

Back in 2015 I wrote a post on unit testing events and callbacks in C# . It covered a real problem: how do you test something that doesn’t return a value, but eventually fires a callback or raises an event? 
 11 years later, I’m fiddling with a little project at home that uses lots of programming languages, and I’m cringing at some of the things I wrote back than. In…

Reading F#

A tweet about some C# code rewritten in F# got me interested yesterday. 
 
 If you know a little F# it’s easy get sucked into thinking that having much fewer lines of code, and less noise generally makes F# code automatically better, cleaner, easier to read than C#. But, of course, that’s only true for people who know enough F# to read it. 
 When I see very smart C# devs unable to…

Unit Testing Events And Callbacks In C#

The Problem 
 When you want to unit test a method it’s usually pretty simple. Call the method, pass it it’s parameters and assert against it’s return value, or some other property of the object that may have changed. 
 What happens when a method doesn’t return a value, or update some property? What happens when it leads (perhaps after some delay) to an event firing, or a callback getting…

Avoid Branches In Your Code

This week at our FunctionalKats meetup in Dublin, we tackled a simple programming task the Luhn checksum algorithm. The challenge was to try and make the code readable. 
 I rattled off some code that worked, but I wasn’t at all happy with it. It implemented the problem as described. Partitioning the numbers into two groups and dealing with each group in turn. 
 let Luhn s = 
 let…

Mastermind: The Code Breaking Game

Grap The Code 
 Mastermind, is a code breaking game for two players. 
 A “Code Maker” creates a secret sequence of colour pegs. A “Code Breaker” must break the code by taking guesses and working with the feedback from the Code Maker. Feedback is given using Black and White Pegs. 
 A correct colour in the correct position is acknowledged with a Black Peg
A correct colour in the…

The Best Job I've Ever Had

Still the best job I’ve ever had and I’ve given up hoping there’ll ever be a better one. My first year at TIC was my first time in the US. Karen picked me up at the airport. On the drive to her house I mentioned Visual Basic, and there and then she decided. We would be teaching Visual Basic. That’s how things worked at TIC. 
 During my second year I suggested we split computing and…

The Challenge Today Is Overwhelming Complexity

Here’s a really great post by Tom Moertel on squeezing every last ounce of performance out of machines back in the day. 
 It was a time when unrolling a loop to save the few clock cycles or seeing a unique way to use the registers of a chip could take a game from clunky to classic. 
 Stories of making machines do the impossible are the stuff of legend. The closest we mere mortals came was…

Choices And Nesting

And so, we arrive at the last post of the series. I’ll show you the F# ‘Choice’ type and show how it relates to active patterns. I’ll explain how to add additional parameters to a multi-case active pattern, and introduce some complex pattern matching using nested active patterns. 
 Look Ma! No Params 
 In the previous post I mentioned that Multi-Case active patterns can’t accept additional…

Multi Case (|A|B|)

Playing Cards are a commonly used example of discriminated unions in F#. I’m not presuming that you already understand Discriminated Unions, but I’m also not going to explain them. You should be able to follow along and get a sense of how they work. If you’d like to read up on them try here. 
 A Rank is something that can have one of 13 values Ace through King. A Suit can have one of 4 values…

Single Partial (|A|_|)

I’ve referred to all of the Active Patterns we have seen so far in this series as ‘Single Total’. It’s time to look at the distinction between ‘Total’ and ‘Partial’ Active Patterns. 
 To understand Partial Active Patterns you need to have some understanding of Option Types’. If they are new to you, I’d encourage you to read up on them before continuing. A great place for reading about this,…

Single Partial With Params (|A|_|) x

We close out the discussion of Single Active Patterns by adding parameters to the partial active pattern. If you’ve read the post on adding parameters to the Single Total Active Pattern then there is absolutely nothing new here, it works in exactly the same way. 
 For that reason I’m not going to use this post to explain how to do it, I’m just going to work through an example and leave it at…

Partial Application

This post was supposed to be about Partial Active Patterns, but before we get to that, I want to take a small diversion to cover Partial Application of Active Patterns (which is a completely different thing). Confused? Don’t worry. Read on. 
 Partial Application 
 I’ve described Partial Application in detail here and here, so I’m going to assume that you know how it works for regular…

Pattern Matching

This is the first in a series of posts explaining Active Patterns, a very cool feature of F#. This post will lay the groundwork by covering pattern matching, and introducing the concept of active patterns. Subsequent posts will cover the various types of active pattern in detail. 
 Destructuring Assignment 
 Thanks to Miles McGuire for setting me straight on the name. 
 F# is full of…

Single Total With Params (|A|) x

We move on to the next in our series on Active Patterns, but this time we’re really just covering a slight modification to the Single Total pattern that we covered in the last post . 
 All the same rules apply, we’re just adding the ability to add parameters to the Active Pattern. 
 I say ‘parameters’ but in reality I mean ‘additional parameters’. Every Active Pattern has at least one…

My 5 Biggest Mistakes

You can’t work in this business for very long before the hope, idealism and intellectual curiosity is beaten out of you and replaced with TPS Sheets, and 15 different tools for telling your colleagues how to configure IIS so that your app will actually run on their machine. 
 If you’re new to this business there may still be time to save yourself. Go drive a truck, or learn a bit about your…

Maps and Sets

In the most recent post in this series I implemented Tic-Tac-Toe using recursion to find the best moves. The point of that post was the recursion and I took the simplest approach I could think of to represent the actual board and moves. 
 I used two lists of ints, one for each player’s list of occupied squares. The board itself wasn’t explicitly represented at all, it could be inferred from…

Fly The Damn Plane

Constant Learning 
 Being a software developer means constant learning. The technical landscape is always shifting. We have to run to stand still. We know this. We accept it. For some it’s the very thing that attracts them to the profession. 
 I’ve learned lots about software development in the last few years. 
 How to automate builds
How to automate tests
Object Oriented…

Single Total (|A|)

Part 1 of this series was mainly sharpening the axe by covering some basics like Pattern matching. I also gave a general sense of what active patterns are (functions that can be used when pattern matching, such as in match expressions). Now it’s time to dig into the details. 
 As I mentioned previously there are arguably 5 variations of active patterns. This post will cover the first of those,…

Recursion

This post looks at a hugely important part of functional programming, Recursion. In simple terms this means writing a function that calls itself. 
 There are endless examples of using recursion to figure out Fibonacci numbers, or process lists. This post will be a little more complicated but hopefully is simple enough that you’ll be able to follow along. 
 We’re going to teach F# to play…

Understanding The Four Rules Of Simple Design

I don’t normally review books, mainly because when it comes to technical books I rarely manage to read them in their entirety. 
 I have however just finished “Understanding the Four Rules of Simple Design” by Corey Haines and since it’s self published, and promoted pretty much exclusively through word of mouth, I thought it might be worth a short review. 
 The “4 Rules” mentioned in the…

The Happy Path

Every movement needs an enemy, it galvanises followers, gives a community a sense of some shared identity. Even if Group A aspire to nothing more than to not be like Group B that is at least something to rally around. 
 “The Waterfall” is increasingly becoming an Alamo for those who aren’t or don’t want to be convinced by talk of “Agile”. 
 For the Agile community the designated enemy…

Don't Scatter Logic All Over The Call Stack

Here’s a problem I come across all the time in legacy code and I have been guilty of it myself in the past. This isn’t going to be rocket science, but, apparently, this stuff doesn’t go without saying. Normal caveats about this being a simplified contrived example apply. 
 Take a look at this code 
 static void Main ( string [] args ) 
 { 
 PrintTradeBalance () ; 
 Console .…

Simplicity

Ladies and Gentlemen of the class of ‘14 
 If I could offer you only one tip for the future, simplicity would be it. The long term benefits of simplicity have been proven by Rich Hickey whereas the rest of my advice has no basis more reliable than my own meandering experience. I will dispense this advice now. 
 Beware the over engineered complexity of your code; oh nevermind; you will not…

Memoization

Imagine you have a long running function that you’d like to avoid running unnecessarily. For the purposes of this post you’ll have to suspend disbelief and pretend that negating a number is an expensive task. This example prints out a message so you can see when it actually gets called. 
 let Negate n = 
 printfn 'Negating '%A' this is hard work' n 
 - n 
 
 val Negate : int ->…

When Can You Start?

He sat in the large bay window observing the potential candidates as they approached the house. His mind was made up about each of them before they rang the bell. 
 “I’m here about the gardener job” 
 “Sorry, the position is filled.” 
 “Already? OK, thanks, bye” 
 Again and again all the same. No good. Then…aha! this one. 
 “I’m here about the gardener job” 
 “When can you…

C# Is Too Damn Noisy

I am growing increasingly frustrated with C#. I think the reason for that may be my exposure to languages like F#. In many ways my feelings for C# are quite similar to feelings I had about VB.Net when I was first exposed to C#. 
 It’s taken me a while to figure out what it is that I find irritating about C# and I think I’m ready to call it. The problem with C# is exactly the same problem I had…

Why Do Cars Have Breaks?

Why do cars have brakes? 
 I noticed this question on Jon Jagger’s blog and I was delighted with myself that I managed to get the “right” answer without peeking. 
 Stop reading right now, have a think about it, then head on over to Jon’s blog to see what he has to say on the topic. 
 Then, if you want, read on… 
 How would you drive if your car didn’t have brakes? Perhaps…

Unfolding Sequences

In my last post I worked through an example that finds the range of numbers that sum to a target value, or gets as close as possible without exceeding the target. I mentioned that the solution felt a little too like the loopy code I would have written in non-functional languages. I felt that there might be a more “functional” way of solving the problem, but I didn’t know what it was.

Iterating, Incrementing, and Accumulating

Another F# session this evening and some more deliberate practice of Functional Thinking. To be fair, this post isn’t really about anything new. If you’ve ever used recursion, even in non-functional languages, this will be old news. If you are new to Functional Programming and/or recursion then this may be useful. 
 Here’s a really simple function. It accepts a number n and sums all the…

Partial Application

Warning, novice functional thinker here. If you know your stuff, what follows may cause distress. 
 I was messing with F# last night and I got a gentle reminder that I’m still a long way from thinking functionally, it still takes a lot of effort. 
 I started with this 
 let evens r = List . filter ( fun x -> x % 2 = 0 ) r 
 > evens [ 0 .. 10 ];; 
 
 val it : int list = [ 0…

Legacy Code Katas

I like Kata’s, I’ve get a lot out of them, but if I’m truly honest, they don’t really address one area of programming where I think I need practice, and that is in working with Legacy Code. In pondering this problem I came to the conclusion that I need a way of doing deliberate practice for legacy code work, and some variation of the Kata idea seems like it might work.

I is for Interface

Back in 1995 I sat in a large ballroom to listen to politicians from the North and South of Ireland talk about the peace process, which at that time was far from a sure thing. 
 A story, told by one of the Unionists stuck in my head. He told of how he had been involved in selling a ceasefire to loyalist paramilitaries and one of the questions that he was faced with was.

The Anagrams Kata

The following is my C# implementation of the Anagrams Kata as described on cyber-dojo.com 
 Write a program to generate all potential
anagrams of an input string. 
 For example, the potential anagrams of “biro” are 
 biro bior brio broi boir bori
 ibro ibor irbo irob iobr iorb
 rbio rboi ribo riob roib robi
 obir obri oibr oirb orbi orib 
 Let’s write a test. 
…

The Pilot and the Project Manager

To land a plane you need to line up with the runway, figure out the right rate of descent and airspeed, then monitor and manage those, all the way down to the ground. 
 Your goal is to touch down on the runway, rather than before or after it, while travelling fast enough that the plane doesn’t stall and fall out of the sky, but slow enough that the wheels stay attached when they hit the…

Are Unit Tests the new Comments?

It’s verging on heresy to even talk of Unit Tests and Comments as being in any way related. They serve different purposes, work in different ways, and have nothing in common. 
 Except 
 Comments 
 
 Document Interfaces, API’s etc. 
 Can drive development by writing pseudo code comments first. 
 Mark outstanding work using TODO comments. 
 Explain particularly…

Getting Functional with F# and The Game Of Life

One session at NDC that really kicked my grasp of functional programming up a few notches was Vagif Abilov’s discussion of Conway’s Game Of Life using F#. 
 I’m not going to rehash the rules of Game Of Life here, if you aren’t familiar with them then read this . 
 Vagif’s source code is on github and his slides are on slideshare . His stuff is well worth a look, but don’t look yet. 
…

You're Not Gonna Fix It

I’m not going to justify kludges, or apologise for kludges. I don’t need help figuring out how to avoid them. Kludges don’t usually come about because we don’t know how to avoid them. They usually exist because we make a judgement call. We decide that a kludge is not worth avoiding. Dress it up any way you like, but it comes down to a decision. 
 This post starts from the premise that in all…

Fluent Mocking

Here’s a scenario (for once not a hypothetical scenario, this is a real system I worked on). I was building a wizard based app. To be more accurate I was building lots of wizard based apps. 
 After a couple of wizards the functionality became clear and I extracted it to it’s own framework. My apps could then focus on actual bread and butter functionality. 
 Two of the objects in my…

Retrofitting Tests To Legacy Code

One problem with TDD is that those who try it, often begin by writing a few trivial tests to get the lie of the land. Then instead of using TDD to write new code they do something much much harder. 
 They do what I did, they start out by trying to write some unit tests for existing code. Either a past project, or more likely the project they are currently working on. Then they discover that…

Contact

Get in touch 
 Thanks for your interest in devjoy.com. Please use this form if you have any questions about our services and we’ll get back to you very soon.

Projects