Javascript programming styles

My current state of thinking:

prototypes make sense if I have many of a thing that has its own state and I want to interact with them individually.

Here’s a terrible off-the-cuff example: a group of addresses, where each needs to be able to display, edit, save, delete, validate, lookup postal code, set/change the nickname. I will interact with just one at a time, but they all do the same thing.

functional makes sense if I am acting on a set of items.

A terrible off-the-cuff example: A set of animated snowflakes on a page. While they could be instances, they all use the same behavior and are probably updated as a group, so they can be an array of data rather than instances. You can perform logic against the group, like filtering to see if any of them have arrived at a surface and should stop animating.

composition makes sense for grouping actions/behaviors.

Convoluted off-the-cuff example: I’m simulating a network, and each device can be a client, a server, a router, a firewall, or some combination of those. I can use composition to assemble the functionality of a particular device when I create or modify it.

mixing these can make sense, too. You can use composition to build prototypes to give you the flexibility to assemble actions and behaviors but still have the reuse of a prototype. You can use functional programming to operate over a set of instanced objects when it makes sense.

Don’t get trapped in a paradigm.

 

 

MonolithFirst

  1. Almost all the successful microservice stories have started with a monolith that got too big and was broken up
  2. Almost all the cases where I’ve heard of a system that was built as a microservice system from scratch, it has ended up in serious trouble.

This pattern has led many of my colleagues to argue that you shouldn’t start a new project with microservices, even if you’re sure your application will be big enough to make it worthwhile. .