Higher Order Programming


Reading time ~4 minutes

Array- or Set-based Coding Style

An Anti-Pattern?

This is an exploration of advantages gained when you code everything as an array. (Using Jedi concepts from SmallTalk)

Here’s some guiding principles:

  1. All input is array-like. Even if an array of 1.
  2. Higher level functions should generally accept AND return arrays. (Except for callback methods for loops: map/reduce/each/filter)
  3. 99 out of 100 devs code suffers from what I call acute schema surplusage syndrome -based models.
  4. Yes, beware fat clASS-backed models - with all the predictable trappings: fragile instance state - so many levers and knobs to mess with, DB transactions, sql locks, async/mutexing (that always works first time), using idiomatic property getter/setters, and your public/private/final/etc usage is solid, right?

  5. So let me take a common problem and shoehorn ~add~ some set-based musings.
  6. A hypothetical Blog Site has lots of Articles, and has even more Posts (Comments).
  7. Let’s add a delete method (below) - but with support for both singular OR arrays.
package net.danlevy.why.java___why.you.got.all.the.dots____it.must.be.all.the.factories;

public class Post {
  public String   title;
  public Date     created;
  public String   message;

  public Post(String title, String message) {
    this.title    = title;
    this.message  = message;
    this.created  = new Date();

  public Date isArchived() {
    return this.created < new Date(2015, 0, 1);

  // Post.delete` can be called w/ a singular Post or an array of Post[]
  public static int delete(Post post) {
    Post<List> posts = new Post<List>(post);
    return delete(posts)

  public static int delete(Post<List> posts) {
    return posts.map(DB.cleanupPost);

Forgive me if my Java is a little rusty.

Work-in-progress (updated Nov. 2015)

HOWTO: Stop creating junk Promises using Composable Javascript

## HOWTO: Stop making junk promises> Please take a look at (& star plz) this article's companion Github project, [Escape From Callback Mo...… Continue reading