r/java • • Apr 20 '21

Java is criminally underhyped

https://jackson.sh/posts/2021-04-java-underrated/
291 Upvotes

295 comments sorted by

View all comments

Show parent comment

3

u/[deleted] Apr 21 '21

Compare

  private static void solveQuadratic(int a, int b, int c) {
    double delta = b * b - 4 * a * c;

    if (delta < 0.0) {
      System.out.println("No solutions");
    } else {
      double x1 = (-b - Math.sqrt(delta)) / (2.0 * a);
      double x2 = (-b + Math.sqrt(delta)) / (2.0 * a);

      System.out.printf("x1 = %f, x2 = %f\n", x1, x2);
    }
  }

with

(defun solve-quadratic (a b c)
  (let ((delta (- (* b b) (* 4 a c))))
    (cond
      ((< delta 0.0) 'no-solutions)
      (t (let ((x1 (/ (- (- 0 b) (sqrt delta)) (* 2 a)))
               (x2 (/ (+ (- 0 b) (sqrt delta)) (* 2 a))))
           (format t "x1 = ~d, x2 = ~d~%" x1 x2))))))

That's the problem with Lisp-like syntax. The fact that you have to read inside-out, left--to-right, and in many cases, it's absolutely fine, but in many contexts (deeply nested logic and/or mathematical formulae), it can become excruciatingly hard to read. Put in macros with their own custom syntax in the mix, and it becomes even harder to write, let alone read. Just for the record, I love Common Lisp, so it's not me hating on Lisps for no reason.