Wednesday 31 August 2016

Design Pattern Haikus


a singleton is
a global variable
sounds a bit better 

A singleton is just a fancy name for a global variable. I like to think of a singleton as a way of warping to another point in space/time, changing the space time continuum and then heading back. You've seen the sci-fi films where this happens, right? It has similar effects on your code, making it difficult to understand what the hell is happening.


interpreter is
domain specific language
that is all it is

Well, there's not much more to say is there? You want your code to be readable in the language of your domain. One way to do this is to make the code look more like the language of your domain. A domain-specific language is one way to accomplish this.


multiple dispatch
that is what you really wanted
visitor will do

You've got a function that wants to do different things depending on the types of the arguments. You've got a language that only allows you to do one different thing via polymorphism. You don't want type-switching cos someone told you that was bad.

Assuming you've got those prerequisites then go for the visitor pattern. Alternatively, look at multiple dispatch and see there's no problem there at all really.


functions compose well
classes do not compose at all
love strategy pattern

You want to break apart a set of work into small discrete components (let's call them "objects"). The strategy pattern allows you to plug these together to solve a problem.

Or... You want to break apart an algorithm into discrete functions (let's call them functions). Functions glue together.

Wednesday 11 May 2016

Professionalism in Software Engineering

Yesterday, I attended a talk by Bob Martin on Professionalism in Code hosted by Software East at Redgate. I also spent considerable time beforehand working out whether it'd be unfair to introduce Bob as the "Donald Trump of Computer Programming". Sanity prevailed and I didn't. But I just wrote it up there, didn't I? D'oh.

Is the software engineering industry professional? As software engineering professionals we should have skill and good judgement. Does the software engineering industry have that?

Bob gave the famous example [PDF] of Knight Capital and Volkswagen, but there's many more (Therac-25, the F35 and The Chaos Report [PDF]). You could argue that the software industry is in meltdown and developer incompetence / poor judgement has cost the industry billions. I think you'd have a pretty convincing case! Or would you? There was no mention the other side - the tremendous advantages our haphazard industry has made to almost the whole planet (the Internet, mobile phones, communication).

Bob painted the nightmare scenario - regulation. Imagine some time from now, some bug somewhere (a missing ; even) results in a number of deaths. The nuclear reactor blows, the self-driving cars go made on a leap year and start running people over, the planes turn upside down when crossing the equator (etc). The natural result of this is the Government blames us (software developers) and starts to put some regulations in place. Again, this feels believable-ish.

But why hasn't it happened yet? Well, safety-critical systems are pretty regulated. See this lump [PDF trigger warning] from the FAA about how they do things. I'm not going to argue it's perfect, but it's demonstrably good enough to stop null pointers making things fall out the sky regularly.

So what should we do to prevent this threat of regulation? Well, we should:
  • Not ship shit!
  • Give reasonable estimates!
  • QA should find no bugs
  • Software should get better, not worse
  • Invest 20 hours per week in personal development
Most of this stuff is easy to agree. Of course we shouldn't ship shit - are you insane? Of course we should strive to write bug free code. If you want to explore these ideas more, Bob's book (The Clean Coder) covers the topics in much greater detail. It was a great talk and got the audience thinking.

Are these the right things to make the industry professional? Maybe. Maybe as an industry we should look at other areas:
There's a huge space for software engineers to explore about building professional quality software. We're not explored much yet. I'm certainly no historian, but I'd imagine professions like Medicine, Law and Engineering took more than 60 or so years to establish what good looked like.

The deliciously chaotic world of software engineering is going to continue for a while yet!

Monday 4 April 2016

Azure Platform Services

Last time around we compiled a large compendium of links detailing Azure Infrastructure services. In this post, we'll compile an even larger set of links detailing Azure's Platform Services (PaaS rather than IaaS).

The breadth of services that Azure offers is pretty overwhelming, so take a deep breath :)

Cloud Compute

Azure Cloud Services allows you to create a compute service (ASP.NET, Python, node and PHP are all supported). This might be a worker role (e.g. a background tasks) or a web role (e.g. simple requests to display data). Cloud Services gives you the ability to scale these horizontally as needed.

Azure Batch runs your large scale parallel tasks and big batch processing jobs. Azure scales these as needed.

Azure Service Fabric is an orchestration layer for micro-service based deployments. It was borne out of internal use at Microsoft used to develop Azure itself.

Azure RemoteApp is a bridging technology (similar to Citrix type things) allowing you to access your application anywhere.

Web and Mobile

Web App Service allows you to deploy web applications in languages like C#, node.js and Python. It's now part of the more general Azure App Service.

API App Service allows you to deploy secured API services and generate appropriate clients to access them.

API Management Service lets you "take any API and publish a service in minutes". More specifically you get monitoring, RESTful and JSON-ful support and the ability to combine multiple back-ends into a single API endpoint.

Mobile App Service gives you an API specifically for mobiles, including support for off-line sync.

Logic App Service lets you integrate business processes and workflows visually. It's goal is to make it easy for you to join your data from on-premise to cloud-based workflows.

Notification Hubs provide scalable push-notifications to all major platforms (including iOS and Android).


SQL Database provides a fully managed PaaS version of SQL Server with advanced features such as an index advisor (monitoring your workload to see access patterns that would benefit from an index).

SQL Data Warehouse is a data warehouse that can scale to huge volumes of data (pricing is based separately on Compute and Storage use).

Redis Cache is the PaaS version of Redis, an in-memory data structure store.

DocumentDB is a store for JSON documents. As of Build 2016, it was announced that there is a MongoDB compatibility layer (see here).

Azure Search provides a fully managed search service (with Lucene query compatibility).

Azure Table Storage provides you with a key-value store aimed at large schema-less documents.

Analytics and IoT

HDInsight is a managed Apache Hadoop (map/reduce), Spark, R, HBase and Storm service made "easy".

Azure Machine Learning is a set of machine-learning API's, allowing you to applying advanced analytics to a wide source of data (pictures, people, text etc.). As of Build 2016, this seems to be in the process of being rebadged "cognitive services".

Azure Stream Analytics gives you the ability to do real time processing of streaming data from huge numbers of sources.

Azure Data Factory is a set of data orchestration API's, allowing you to mangle data from different sources together (with tools for data lineage, ETL and so on).

Azure Event Hubs is a scalable pub-sub service for aggregating events from many sources.

Mobile Engagement is a set of API's for monitoring and understanding app usage on mobile devices.

Friday 1 April 2016

Azure Infrastructure Services

Azure “is a growing collection of integrated cloud services for moving faster, achieving more, and saving money”. Well, that’s the marketing lingo, but what are the actual services available?

The diagram above, from here, is the best example I've seen of capturing everything that Azure is and the services that it offers.

Let's start with the infrastructure services.

Infrastructure services (IaaS) abstract away physical machines to services that can be molded via code rather than plugging in cables.

Under the banner of Compute, there are a couple of services. Azure Virtual machines let you deploy images in any way. They aren't just limited to Windows, support includes Linux, Oracle IBM and SAP. Azure Container Service allows you to deploy containers to Azure. This is heavily open-source friendly and allows you to use Apache Mesos or Docker Swarm to orchestrate.

There's many options for file storage as a service. Azure Blob Storage provides a service for storing large amounts of unstructured data that can be accessed via http(s). A blob account has multiple containers (think of these are folders or organizational units) and each container can lumps of data (blocks, append-only, page blobs). Azure Files provides fully managed file shares using the standard SMB protocol. This allows you to migrate file shared-based applications to the cloud with no changes. Finally in the storage offerings there are a variety of low-latency and high throughput storages referred to as premium storage. These are essentially pre-configured virtual machines with optimized technology (e.g. SSD) for storage. Options include hosting SQL Server, Oracle, MySQL, Redis and MongoDB.

There's a whole raft of networking services. Azure Virtual Network provides an environment to run your machines and applications where you can control the subnets, access control policies and more. Azure Load Balancer does exactly what it says on the tin - it's a Layer 4 load balancer that allows you to distribute incoming traffic. Azure DNS is another Ronseal service! ExpressRoute lets you create private connections between your data center and Azure data centers (giving you up to 10 Gbps). Traffic Manager is similar to load balancing, but with more flexibility around failover, A/B testing and combining Azure / on-prem systems. Azure VPN Gateways is another virtual network manager, and Application Gateway is an application level load balancer. 

Confused yet?

Monday 18 January 2016

Evolutionary Design Reading List

Evolving a shared library with an API in flux is a tough problem, but there’s plenty of principles, practices and patterns around this.

Parallel Change - Parallel change, also known as expand and contract is a pattern to implement backward-incompatible changes to an interface in a safe manner by breaking the change into three distinct phases: expand, migrate, and contract.

Postel’s Principle - Be conservative in what you send; be liberal in what you accept.

Refactoring Module Dependencies - Some patterns for refactoring module dependencies

Package Management Principles - Principles of packages (REP, CCP, CRP, ADP, SDP, SAP).  Think of these as a higher-level version of SOLID.

Strangler Application - A metaphor describing growing a new system around the edges of old.

Asset Capture - A strategy for migrating between a strangler application and back again.

On the Criteria to be used in Decomposing Systems into Modules - Parnas’ classic paper on modular systems (referenced by Tim in his recent talk).

Escape Integration Test Syrup - Talk from Agile on the Beach about testing and rapidly changing dependencies.

Semantic Versioning - For completeness!