Mitch A
Mitch A

Reputation: 2098

Design patterns for building loosely-coupled systems in dynamic/scripting languages

I have lots of experience building enterprise apps using Java/C# and have become accustomed to all the trappings that come with object-oriented, statically typed languages. Specifically, I've become quite adept at dealing with system complexity by using the standard tools of the trade:

I'm being asked to engineer a fairly complex back-end message processing system using a dynamic, functional language (Lua). Functional languages are all the rage these days (NodeJs, JavaScript etc), so I'm happy to use this as an opportunity to jump on said bandwagon.

Can anyone suggest a sample application or architecture I can use to learn about using things such as first class functions, closures, currying to build a complex, loosely coupled system?

Many thanks!

Upvotes: 2

Views: 1419

Answers (2)

Mitch A
Mitch A

Reputation: 2098

I've done a quite a bit of research on "design patterns" that can be applied in dynamic languages with first class function support, and here are my findings.

Currying == Dependency Injection. Currying allows you to take a function and repackage it as a new function with one or more of its parameter values already assigned. This is very similar to an IoC container instantiating a class "bootstrapped" with all it's dependencies and ready for consumption by clients.

First Class Functions == Command pattern. Since first class functions can be passed around like values, you basically get the Command pattern for free and without the overhead.

References:

First Class Functions == Command pattern

Functional Dependency Injection via Currying

Upvotes: 2

Amir Abu Shareb
Amir Abu Shareb

Reputation: 164

I will suggest looking on the libs/frameworks below, they are really well designed, keep in mind that javascript and lua are very similar, just replace objects with tables add coroutines and "nice" syntax and you have Lua.

Lua

node.js

  • Express micro web framework.
  • Mocha Unit testing framework.

Upvotes: 2

Related Questions