• 0 Posts
  • 4 Comments
Joined 1 year ago
cake
Cake day: July 3rd, 2023

help-circle


  • I’m really surprised to see Java ranked as less-verbose than OCaml.

    Here’s an equivalent code sample in Java 17 vs OCaml:

    Java:

    abstract sealed class Expr permits Value, Add, Subtract, Multiply, Divide {
      abstract long eval();
    }
    record Value(long value) extends Expr {
      @Override
      long eval() { return value; }
    }
    record Add(Expr left, Expr right) {   
      @Override
      long eval() { return left.eval() + right.eval(); }
    }
    record Subtract(Expr left, Expr right) {
      @Override
      long eval() { return left.eval() - right.eval(); }
    }
    record Multiply(Expr left, Expr right) {
      @Override
      long eval() { return left.eval() * right.eval(); }
    }
    record Divide(Expr left, Expr right) {
      @Override
      long eval() { return left.eval() / right.eval(); }
    }
    

    OCaml:

    type expr = 
      | Value of int
      | Add of expr * expr
      | Subtract of expr * expr
      | Multiply of expr * expr
      | Divide of expr * expr
    
    let rec eval = function 
      | Value value -> value
      | Add (left, right) -> (eval left) + (eval right)
      | Subtract (left, right) -> (eval left) - (eval right)
      | Multiply (left, right) -> (eval left) * (eval right)
      | Divide (left, right) -> (eval left) / (eval right)
    

    …Java has so much more syntactical overhead than OCaml, and that’s even with recent Java and being pretty aggressive about using boiler-plate reducing sugars like Records. And F# has even less, since it doesn’t require you to use different operators for numerics or do as much manual casting between strings/numerics


  • Conversely, I have a recent-ish (<5yrs old) Brother inkjet printer that’s waiting to be dumped to recycling because it arbitrarily decided that it didn’t ever need to be discoverable or respond to any print requests one day, and so even though there was nothing mechanically wrong with it, even hooking up a Raspberry Pi to run CUPS over USB didn’t fix the issue – because Brother explicitly refuses to publish drivers for the Raspberry Pi, and their inkjet drivers are proprietary.

    I’ve since replaced it with the best-reviewed Epson printer I could find that supports a generic PCL driver, so that if Epson ever loses their minds in the way Brother did, I can fall back on an open-source implementation of good ol’ PCL.

    That thing’s given us no issues so far.