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

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

Interface mania: Considering when to add an interface for class.

Something introduced fairly early in programming courses is the concept of an interface. In practice interfaces help to define the boundaries between components of a system, define the behavior of underlying implementors of the interface, and make it easier to switch implementations of said behavior down the road. Today’s post offers a few thoughts on where interfaces should and should not be used. ...

September 26, 2014 · MichaelHughes

Java ArrayList resize costs

Today we will look at whether it’s worth developer time to pre-size ArrayList objects in Java application code. We will take a similar approach to the one taken in a prior post on how long it takes to handle an exception in Java. ...

September 11, 2014 · MichaelHughes

How long it takes to throw an exception in Java

Today post is exceptional, we’ll take a brief look at the time cost of throwing and re-throwing exceptions and put that time cost in context. To be specific, we’ll look at the timing information for a set of exceptions which might be found in a typical 3-tier business application. In our example the exceptions are thrown and caught in hierarchical order in order to promote separation between the tiers of the application. ...

September 1, 2014 · MichaelHughes

Server-client date time management in web applications

Previously we have discussed one approach and gave some implementing code for providing time zone adjusted date times to client web applications. Within the space of user facing web applications there are few different approaches to handling the storage and transmission of date time information. Today we will look at a couple broader themes for delivery of date times to client applications from servers and some thoughts on how to do it well. ...

July 25, 2014 · MichaelHughes

On the use of AWS DynamoDB

In today’s post I’ll cover some of the potential use cases for AWS DynamoDB, why you might want to use it or not. ...

June 7, 2014 · Michael Hughes

Create an object based dual list shuttle with Knockoutjs

A quick tip post on using Knockoutjs to create a certain type of common web UI component. The short and sweet summary is that I’ll show how to create a shuttle control using two select boxes that are bound to arrays of Javascript objects (instead of simple value types) using Knockoutjs. Before getting to that though I’ll provide some background on the various component used to create the UI. ...

May 24, 2014 · MichaelHughes

Slicing vs. aggregating big data

So you have a lot of data from something. What’s happens next? Where does the data go after point of capture? The data in question could be analytics gathered from application performance, click logs from a website, search data from a search engine, traffic flow data from a state agency’the point being that there is a lot of it. The given examples share use cases with some of the things covered by the much abused phrase “big data”, this post will touch on that concept lightly. The main point of today’s post though is to briefly cover one approach to thinking about how to store a bunch of data whatever it happens to be. ...

March 30, 2014 · MichaelHughes