NodeJS modules should export object constructors

Note I didn’t say always should export objects, but for the sanity of everyone involved, in many cases a required module should return a constructor and not a fully instantiated object. Today’s post is about why your NodeJS modules should look like this: /** * @constructor */ function myConstructor(someDependency) { /* setup my object here */ } module.exports = myConstructor; and not this: var myObj = { myService: new MyService() }; myObj.myFunction = function(foo) { /* do stuff with foo here */ }; module.exports = myObj; ...

October 3, 2015 · MichaelHughes

Logging and Monitoring

Operational monitoring of a software application is one of the activities the ensures a successful public launch. Too often it seems like a service’s course to public availability looks something like, Conceptualization → Development → … → SHIP IT. The “…” component is an important step at large enterprises with large public services (like Expedia, Amazon.com, etc) and involves developing a way to monitor an application whilst running it. At smaller organizations though I have seen this smaller step get discarded or not looked at. Today’s post offers a few thoughts on what logging and monitoring looks like today. ...

June 28, 2015 · MichaelHughes

SRV records as service locators

Recently I began work on a project to manage the deployment of a product built using a microservices architecture. As a result of our chosen architecture we have a large number of services which will communicate to each other over HTTP/S. Instead of using fixed IPs we decided to used DNS SRV records to indicate where services could contact their dependencies. Today’s post goes into using SRV records in a little more detail and the problem they solve. ...

May 2, 2015 · MichaelHughes

Loading a Cocos Studio scene into cocos2d-x 3.4/3.5

In the last few weeks I have been slowly learning about the cocos2d-x framework. cocos2d-x is a C++ based cross platform game engine. The makers of the engine also produce a UI creation GUI called Cocos Studio. Today’s post is a brief one about loading scenes from Cocos Studio into a cocos2d-x based application. ...

April 25, 2015 · MichaelHughes

Loops in NodeJS

I’ve written before about how it’s better to write straightforward code than trying to be clever and pre-optimize. Another example of where this rule is true is the cost of iteration between different styles of array loops in JavaScript when executed within NodeJS. ...

March 15, 2015 · MichaelHughes

The importance of being mindful of operator precedence

Operator precedence determines the order [Operator precedence determines the order]2 and binary operators are executed. In many situations, knowing basic mathematical operator precedence (for +,-,*, etc) is enough. In other situations not knowing the specifics of language can lead to hard to find errors. Quickly, in JavaScript what does 'the boogeyman ' + false ? 'is scary' : 'is not scary' evaluate to? ...

January 21, 2015 · MichaelHughes

Using Olingo ODataJS 4 Beta with AngularJS and Web API OData V4

Recently I started writing a new web application which uses OData V4 as the protocol for passing data to back and forth between the JavaScript client and ASP.Net server. The client is written using AngularJS which doesn’t have any built-in facilities for working in OData APIs. In order to avoid writing my own OData message handler I used the Apache Olingo library to handle the grunt work of sending requests and receiving responses. I wanted to encapsulate the Olingo library in an AngularJS service in order to make using it easier, the following post details how this was done. ...

January 5, 2015 · MichaelHughes

Repository pattern overuse: The double repository with Microsoft Entity Framework and other ORMs

Martin Folwer’s blog and website is a common reference for modern design pattern so we will start with his glossary definition for the repository pattern. The linked article contains more detail, but in short a ‘repository’ acts as an data store layer on top of the storage system and provides (more) object oriented methods for accessing said system. Unfortunately, something I have also seen is the over application of this pattern in combination with RDBMS ORMs leading to contorted code with unnecessary interfaces and classes. This post covers what I have seen in some projects in order to provide some of the code smells to avoid. ...

January 4, 2015 · MichaelHughes

Of null VARCHAR fields and empty strings

How to represent a blank user input is a reasonably innocent design question. On a couple occasions though I have been bitten by systems that have been designed without considering that question seriously. Maybe it’s a clear choice to some, but today’s post makes an argument that in representing an empty input as a null is better than using a empty or blank string. ...

December 1, 2014 · MichaelHughes

Agilefall: gracefully delivering (some part of) a project on a fixed deadline

IT consulting is an odd place to be when it comes to software engineering practices. We often end up writing software for business groups that have fixed budgets and more importantly fixed deadlines. We also try to follow an agile methodology for software development that roughly follows scrum (warning: PDF), but with defined roles for a project manager and a development lead. Today’s post discusses some of the difficulties seen in using Agile to deliver business software and how we can mitigate those difficulties, basically things that worked and things that didn’t. ...

November 30, 2014 · MichaelHughes