I was looking at code.golf the other day and I wondered which languages were the least verbose, so I did a little data gathering.

I looked at 48 different languages that had completed 79 different code challenges on code.golf. I then gathered the results for each language and challenge. If a “golfer” had more than 1 submission to a challenge, I grabbed the most recent one. I then dropped the top 5% and bottom 5% to hopefully mitigate most outliers. Then came up with an average for each language, for each challenge. I then averaged the results across each language and that is what you see here.

For another perspective, I ranked each challenge then got the average ranking across all challenges. Below is the results of that.

Disclaimer: This is in no way scientific. It’s just for fun. If you know of a better way to sort these results please let me know.

  • philm@programming.dev
    link
    fedilink
    arrow-up
    17
    ·
    2 years ago

    On another look, though, we have to keep in mind, though that this is code-golf, so in no way representative for actual code-bases.

  • expr@programming.dev
    link
    fedilink
    arrow-up
    13
    arrow-down
    1
    ·
    2 years ago

    Haskell being so high really doesn’t make any sense. Experience level maybe?

    It’s one of the tersest languages out there.

  • spencerwi@lemm.ee
    link
    fedilink
    arrow-up
    11
    arrow-down
    1
    ·
    2 years ago

    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

  • colonial@lemmy.world
    link
    fedilink
    arrow-up
    9
    ·
    2 years ago

    I’m surprised C is so low. I feel like I need to write 5x more code (compared to C++/Rust) to do the exact same thing.

    • coloredgrayscale@programming.dev
      link
      fedilink
      arrow-up
      8
      ·
      2 years ago

      Assembly would be lower. You have more complex / direct instructions in assembly. Brain fuck is pretty much just a pure turing machine, and has 8 instructions.

      X86 has ~ 1000 + variants. Even ARM with a smaller instruction set has 232 instructions.

      In brain fuck to set a number you’d have to count up (or down - underflow) to that number. In assembly you just set it.

      Somewhere I’ve read that current assembly code with Makros should be similar to writing C.

  • floofloof@lemmy.ca
    link
    fedilink
    English
    arrow-up
    6
    ·
    2 years ago

    Is Dart inherently verbose, or does it just seem that way because people are using it to make Flutter widgets and they’re verbose? When you look at the Dart syntax it doesn’t seem like it needs to be verbose, but Flutter code certainly can be.

  • ydieb@lemm.ee
    link
    fedilink
    arrow-up
    5
    ·
    2 years ago

    Interesting that zig is so much lower than c in expressiveness. Isn’t that a bit weird?

  • yggdar@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    2 years ago

    With my professional experience in COBOL, I can honestly say I’m not surprised at all!

  • Gamma@programming.dev
    link
    fedilink
    English
    arrow-up
    4
    ·
    edit-2
    2 years ago

    It’s interesting, the results here are way different than the Code Golf & Coding Challenges Stack Exchange. I would never expect Haskell to be that low. But after looking at code.golf, I realize it’s because I/O on CG&CC is more relaxed. Most Haskell submissions are functions which return the solution.

    Sidenote: I like the CG&CC method, it’s semi-competitive, semi-cooperative.

    • all languages welcome
    • almost all users post “Try it Online”/“Attempt This Online” links
    • most users post explanations under their submissions
    • often people will post solutions beginning with “port of user1234’s excellent Foolang answer” when there’s a clever shortcut someone finds
    • or people will post their own solution with “here’s a solution which doesn’t use user1234’s algorithm
    • or people will add comments to answers with minor improvements

    IMO It’s geared towards what is the best part about code golf: teaching people about algorithm design and language design.

    • u_tamtam@programming.dev
      link
      fedilink
      arrow-up
      5
      arrow-down
      1
      ·
      2 years ago

      we hated studying that shit

      It’s a more than fine functional programming language if you ask me. Was that the functional aspect that you disliked? Or the syntax? Because in one case like the other I’ve got some bad news for you about what’s to come in the programming languages landscape :)

      Who tf uses OCaml.

      The rust compiler (initially), large financial companies, the energy sector, etc: practically anywhere functional programming shines

      written by a Scala programmer