Mindless Rambling Nonsense
Paul D'Ambra
pauldambra on github
pauldambra on twitter

Remove If With Objects

Today I had super-fun spotting the opportunity for a refactoring and figuring out how to apply it. I wanted to think it through while it was fresh in my mind to try to cement any learning opportunity

The refactoring in question is "Replace Conditional Dispatcher with Command".

Quoting that source the opportunity for this refactoring is when:

Conditional logic is used to dispatch requests and execute actions.

And the solution is:

Create a Command for each action. Store the Commands in a collection and replace the conditional logic with code to fetch and execute Commands.

It's one of those subtle changes that has real power to tidy up and add to the expressiveness of your code.

If (pun intended) you aren't familiar with it I'd definitely recommend trying it on for size by looking for an opportunity to apply it in your systems.

Powershell on Linux

MS have open-sourced powershell and made it work on many platforms. Kudos to them - I'm loving the "new MS".

I've never really got powershell. Although it's definitely an improvement on vbscript so I have used it when I've needed to automate windows.

But as a task approaches some ill-defined level of complexity I switch to C#, Ruby, or Node rather than writing a script. Not that those are the only options but I don't know Perl, or Python, or $yourFavouriteTool.

As a result I have barely written any Powershell on Windows and, as I've done more work on Linux over the last few years, I've also barely written any bash.

So, while I think it's a good thing that MS are opening up and releasing cross platform tools I was underwhelmed. But…

Real vs. Software Engineering

I recently had some "fun".

Earlier this year we got a great deal on two ducks, three chickens, a coop, a run, and Gary the Rescue Cockerel

Reactotype Part 3

At the end of the last post I realised I'd sacrificed some good practice in the rush to make it work (i.e. worked normally like all those other guilty software engineers everywhere everyday.) So earlier today I played with the kids to tire them out enough that I could distract them with television and write some #holidaycode because I am a good(-ish) parent.

I managed to

  • switch from using magic strings in the messagebus channel and topic identifiers
  • remove some duplication
  • and get some tests around ReactJS

Reactotype Part 2

I posted about my impressions of working with React slowly building an HTML table and banging on about it. I ended that post with one of the more memorable cliff-hangers in recent time.

Sorting and Filtering the Table

That we will leave till part two… because I introduced a relatively artifical constraint that I didn't want the filtering control to be a part of the table.

Imagine that there will be many tables with the same filter. I don't want to bind the filter to any one table or insist that every table has it.

At first I expected that it would force me to understand React's components and how to compose them… instead I stumbled on something really cool #cliffhanger

Exciting! Right?

I want to add a filter control and I don't want it to be bound to a particular table so that it can be re-used.

Reactotype Part 1

part one because I've got a feeling this is a topic about which I'll be able to bang on.

React JS was made by Facebook to be the V in MVC. In other words it only deals with the UI. It's sold as being fast - both for performance and development. A definitely contentious part of React is that it mushes JS and HTML together… More specifically you put HTML inside the JS not vice versa.

Fun With Structs

We had a brief conversation at work the other day about extending a type to make our code clearer…

public class MeaningfulName : MathsName
    public MeaningfulName(double w, double x, double y, double z) : base(w, x, y, z)

Happy Numbers

I love C# but while we're trying to beat our deployment process into submission at work I'm only really writing Ruby and Powershell. So when a few, different articles about the Happy Numbers kata turned up on my twitter feed and I found myself with a large whisky and a sleeping family I thought I'd have a go.

The Happy Numbers kata is defined as

Choose a two-digit number (eg. 23), square each digit and add them together. Keep repeating this until you reach 1 or the cycle carries on in a continuous loop.

If you reach 1 then the number you started with is a “happy number”.

Can you find all the happy numbers between 1 and 100?

Transforming web.config values with Rake

I've really been enjoying using Albacore Rake instead of MSBuild at work. It's enabled us to get everyone involved (because ugh, msbuild xml) and to improve our CI/CD pipeline.

Today we were talking about reducing the number of build configurations we have… which we only have in order to support config transforms.

Static Factory Methods FTW

It is relatively common to find (or write) a line of code like this

	var thingy = new Thingy(_someDependency, false);

Reading this line a person can know this is initialising a Thingy which takes a dependency on something… and something else is false. I'm really lazy and easily distracted so I don't like to have to think about anything except the one task I'm trying to not get distracted from. Having to think about what it means that something is false provides an opportunity for me to get distracted.