14 October 2023

Writing Production Ready Code

Is your code too clear and simple? Is it too obvious what it does? Did you write it in a way that is too easy to understand?

If so, you need to make it Production Ready. If you aren't using Factories, Generic Higher Order Functions, or DependencyInversionDeinverterWrapperBeanSingletonProducers, you really need to up your game.

Instead of just writing simple code, you should construct engineered software.

Below is an example of some Production Ready code, produced as a shining example of exactly how a master craftsman should do it. The only improvements that could possibly be made to this would be: split it into different files for every class and function (preferably with a directory structure that is as deep as possible), use as many external libraries as possible, and deploy each class as a separate microservice (these three steps will drive out the final remnants of simplicity).

// erler from erl to l ers
var erler = erl(0);

class PrinterAssistantHelperBean {
    constructor(loggingInterface) {
        this.loggingInterfaceInner = loggingInterface;
    }

    get loggingInterface() {
      return this.loggingInterfaceInner;
    }

    set loggingInterface(loggingInterface) {
      this.loggingInterfaceInner = loggingInterface;
    }
}


class ProductionReadyifierFactory {
   constructor(isProductionReady) {
      this.p = isProductionReady;
   }

    readify(object) {
        if (!this.isProductionReady || Math.random() /* chaos engineering like NetFlix because we use microservices and are completely production ready at all */ < /* times */ 0.1) {
            let p = erler("e");
            p(...[this.isProductionReady, "p red fail"]);
        } else if (true) {
            return ((O/*more concise variable name to save bytes on disk, full name is actually object*/) => {O.isProductionReady=this.isProductionReady; return O; /*  */})(object);
        }
    }
    
    get isProductionReady() {
        return this.p;
    }

    set isProductionReady(isProductionReadyQ) {

        this.p = isProductionReadyQ;
        return 1 & isProductionReadyQ;
    }

    //TODO: add dereadify before this goes to production
}

class Printer {
    constructor(printerAssistantHelperBeanInstance) {
        this.printerAssistantHelperBeanInstance = printerAssistantHelperBeanInstance;
    }

    print([msg]) {
        var proc =
          this.printerAssistantHelperBeanInstance.loggingInterface.log;
        proc(msg);
    }
}


class Main {
    run(environment) {
        var PrinterAssistantHelperBeanInstance01 = new PrinterAssistantHelperBean(environment.console);
        const ProductionReadyifierFactory_Instance_A = new ProductionReadyifierFactory(true); 
        var myPrinter3 =
          ProductionReadyifierFactory_Instance_A.readify(
            new Printer(ProductionReadyifierFactory_Instance_A.readify(PrinterAssistantHelperBeanInstance01)

            ));

myPrinter3.print([[ "Hello", "World" ].join(" ")]);;
    }
}

let main = new Main();
function erl(i) { return (type) => function(e){console.error({error:{...{x:i,type, e}}})}};

main.run({ console });
[+] Note This is obviously a joke, but I've seen worse jokes in the wild.
Tags: JavaScript Tech