Hacker News new | past | comments | ask | show | jobs | submit login

There aren't many languages that have radically fewer parentheses than Clojure / LISP.

Clojure:

    (defn blub-extra [a b]
        (blub (inc a) (inc b))) 
8 parens + 2 brackets

Scala:

    def blubExtra(a: Int, b: Int): Int {
       blub(inc(a), inc(b))
    }
8 parens + 2 braces

Java:

    Integer blubExtra(Integer a, Integer b) {
        return blub(inc(a), inc(b));
    }
8 parens + 2 braces

Ruby:

    def blubExtra(a, b)
        blub(inc(a), inc(b))
    end
8 parens

Python:

    def blubExtra(a, b):
        return blub(inc(a), inc(b))
8 parens, one colon

C:

    int blubExtra(int a, int b) {
        return blub(inc(a), inc(b));
    }
8 parens + 2 braces

It's roughly the same numbers of brackets (or equivalent) in Clojure, Scala, C and Java. A bit less in Python and Ruby.




Scala example is wrong, wouldn't even compile; should be:

    def blubExtra(a: Int, b: Int): Int = blub(inc(a), inc(b))
The original would need an equals thrown in there, otherwise it's procedural syntax (IIRC, has been deprecated or will be in the next release) which has a return type of Unit, thus not compiling when specifying a return type of Int.

    def blubExtra(a: Int, b: Int): Int = {
      blub(inc(a), inc(b))
    }


Thanks for the typo spot. I've not written Scala for about 5 years. Unfortunately I can't go back and edit my post.


You can do it in Ruby with 4 parens, or even 0 if inc is really just +1. I wouldn't ever write it with so few but if we're really going down this rabbit hole then we ahould get it right.


Please feel free to contribute a Ruby example (as long as it's normal and idiomatic, this isn't a competition)! I've not written Ruby for years.

(inc was just a random function for the sake of showing invocation so it's not really fair to use operators)


I think it's the positioning of them that makes them stand out to people, plus the fact that they tend to bunch up at the end of things.


Of course, I know. But most people express it as 'too many parens', without (I believe) actually thinking too hard. I was just trying to provoke a few thoughts!

The position of parens is something to get used to, but then again so is Python's indentation, Scala's type system, etc etc. Every language has something unique to get used to.


as someone already pointed out on twitter:

F#:

let blubExtra a b = blub (inc a) (inc b)

4 parens.


Usually we would write it as:

let blubExtra a b = inc b |> blub (inc a)

which 2 parens less, but at the cost of using the (very idiomatic) pipe operator.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: