Skip to main content

Posts

Showing posts from August, 2015

Production Code is Dirty

Production code is dirty. Dirty may be the wrong word however. Complex could be more suitable. Unlike code that is not yet in production, it is weathered, proven, and full of edge cases including numerous bug fixes. After some time this build up of additions can cause the code to be considered dirty or legacy.Greenfield development used to appeal so much more. Small classes. Small methods. Few dependencies. Just simple, clean code. Except this is not the case. Get into production and that clean code starts to weather. You'll handle edge cases, fix bugs and stabilize the functionality. That lovely, small, well factored application starts to accumulate dirt. The new code smell wears off and you're back waiting for the next new project so you can do it properly a second time around.This does not have to be the case however. Long living software such as operating systems, browsers and embedded systems are maintained and extended well after they were created. Production code can be…

Queue Centric Work Pattern

The Queue Centric Work Pattern (QCWP) is simple. Send a message declaring the intent of the command, acknowledge the message and proceed. All work takes place in a background process so the user is not kept waiting for the request to return. Acknowledgement usually takes the form of persistence to ensure that no messages are lost. Real life examples of the QCWP in action would be the sending of an email or the confirmation of an order being accepted from an online retailer.The QCWP will introduce the concept of eventual consistency, which surprisingly is not an issue in most cases. The queue itself should be implemented via some form of message queue that handles some of the more complicated technical issues regarding message meta data, routing, persistence and so on. Once a message queue has been chosen the code required to implement QCWP does not differ to far from simple request-response examples in terms of both complexity and lines of code.BenefitsReduced LatencyTransferring the …

Loops vs Functional Programming Styles

The following examples are four of the most common functional programming patterns that appear in mainstream languages though they may be known under different names.Being a fan of CQS and CQRS, queries work great when coding using the functional style. While this is completely subjective in terms of style there is another benefit - composition. In other words the functional styles below can all be joined together with minimal changes. A traditional loop would require additional modifications. The benefit composition provides is similar to the pipes and filter architecture - it is very easy to change the behaviour of the pipeline by simply adding or removing statements.Composition and concise code aside, traditional loops should not be avoided fully. Each scenario will have different solutions. Sometimes you really just want a standard loop.The benefit of learning the key concepts behind Map, Filter, ForEach and Reduce is the ability to translate these styles and idioms into other lan…

Why I Don't Like Mocking Frameworks

Disclaimer: By mocking framework I generalize anything that includes support for stubs and mock objects.The use of mocking frameworks was a difficult part of my TDD journey. Not only are newcomers expected to get their head around the basics of the practice there are now new tools to contend with. To make matters worse there is a lot of mocking frameworks out there with differing quality qualities and suitability.The use of mocking frameworks includes a variety of disadvantages.Readability suffers in most cases. You often find yourself asking what is exactly happening here? The frameworks themselves usually impose these constraints and make the issue worse.The use of frameworks tends to lead to header interfaces and not role interfaces being used. IDE's usually have a factor in this as they make this anti pattern so very easy to introduce.A lot of developers are not aware of what these frameworks are doing behind the scenes. This can lead to confusing tests and a general lack of u…