by afandian · 11y ago · 0 comments
Clojure:
(defn blub-extra [a b]
(blub (inc a) (inc b)))
8 parens + 2 bracketsScala:
def blubExtra(a: Int, b: Int): Int {
blub(inc(a), inc(b))
}
8 parens + 2 bracesJava:
Integer blubExtra(Integer a, Integer b) {
return blub(inc(a), inc(b));
}
8 parens + 2 bracesRuby:
def blubExtra(a, b)
blub(inc(a), inc(b))
end
8 parensPython:
def blubExtra(a, b):
return blub(inc(a), inc(b))
8 parens, one colonC:
int blubExtra(int a, int b) {
return blub(inc(a), inc(b));
}
8 parens + 2 bracesIt's roughly the same numbers of brackets (or equivalent) in Clojure, Scala, C and Java. A bit less in Python and Ruby.
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))
}(inc was just a random function for the sake of showing invocation so it's not really fair to use operators)
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.