News for hackers. Stuff that matters.
Re:Clojure is cool by ken on Sunday September 09, 2018 @11:42AM (#17946389)
Studies have found that bug count is roughly proportional to program length, across languages. Saying you prefer verbosity essentially means you prefer more bugs. 500 lines is generally less understandable than 40 lines. There may be cases where terseness can be too extreme, but I don't see it here.

Is there some particular aspect of the Clojure code here that you think is overly clever, or hard to understand? This Clojure code uses only one lambda, and in a straightforward way.

I've written a lot of Java, and a moderate amount of Clojure, and if I had to place a wager on which version had fewer bugs, I'd definitely bet on the Clojure. Especially if there were the possibility that it was related to threads.

We could write this in assembly language, and it'd take 50,000 lines, and probably have lots of bugs. The salient point is not (just) the lower line count, but that when code is shorter, that's a good indicator that it's written at a level of abstraction that fits the problem.

Re:Clojure is cool by stickfigure on Sunday September 09, 2018 @02:05PM (#17947018)
I looked over the first example in the article and I don't think this assessment stands up. The Java example could easily be written with reflection and end up quite a lot shorter than the Clojure example.

Sure, you can trade off static typing for terseness. This isn't a Java vs Clojure issue. You can make code even terser by abandoning documentation. Even more terse by abandoning tests!

I don't have time to fully dive into the second example, but at first glance it looks like poorly written Java. You can write Java in a functional style! It can look a lot like Kotlin or Scala or even Clojure, and I generally prefer it to.

Badly written code looks terrible in every language.

Re:Clojure is cool by nescoiquid on Sunday September 09, 2018 @12:06PM (#17946486)
And studies show that the number of lines of code a developer puts out in a day is basically constant across all languages. This is usually cited as an argument for more expressive languages.

But if bug count is proportional to LOC and LOC per day are constant across all languages, then bug per day will also be constant across all languages.

You can write shit code in any language. I used to think Java made it harder to write shit code, but the project I'm on right now has made be reconsider this opinion.

Re:Clojure is cool by bunderbunder on Sunday September 09, 2018 @02:29PM (#17947111)
If bug count is proportional to LOC and LOC per day are constant across languages, then bugs per day might be the same. But you'd still expect features to be getting implemented at a higher rate, and you'd expect a lower bug count per feature. That's ultimately the metric that's most interesting from a business perspective.

IME, the bugs are also easier to deal with in the more expressive language. They tend to be things like faults in the business logic or gross edge cases that people are likely to catch in code review or QA. Whereas the bugs in languages like Java seem to typically be really annoying things like off-by-one errors, comparing Integers with ==, and goofy run-time type errors that sail past the compiler because of weak static type checking when generics are at play, and also past code review because people aren't expecting to have to review for type errors when they're using a static language.

Re:Clojure is cool by nescoiquid on Sunday September 09, 2018 @05:50PM (#17947960)
> But you'd still expect features to be getting implemented at a higher rate

Yes, I'm inclined to agree, but I actually haven't ever seen a study which compares the same project implemented in different languages to establish in toto the variance in SLOC. It could be the case that in the main for the same project the differences between languages wash out, as different languages may have different advantages and disadvantages that are more likely to tell on a substantive project.

What you suggest seems reasonable, but I simply don't know it to actually be the case.

Re:Clojure is cool by erokar on Sunday September 09, 2018 @12:40PM (#17946646)
> But if bug count is proportional to LOC and LOC per day are constant across all languages, then bug per day will also be constant across all languages.

Of course -- but the important thing is that bug count per feature/app will be lower in a more expressive language.

Re:Clojure is cool by lostcolony on Sunday September 09, 2018 @12:50PM (#17946683)
Bug count per day is constant...but functionality per line of code is higher with the more expressive language.

Umm...so for the same amount of bugs I can have more features if I choose the more expressive one...

Re:Clojure is cool by earenndil on Sunday September 09, 2018 @12:24PM (#17946580)
> There may be cases where terseness can be too extreme

I don't know about that, a lot of people seem to like j[1]

1: http://www.jsoftware.com/

Re:Clojure is cool by dcu on Sunday September 09, 2018 @11:48AM (#17946413)
can you link the studies? I'm genuinely interested
Re:Clojure is cool by AdieuToLogic on Sunday September 09, 2018 @12:21PM (#17946568)
Here are a few which are relevant:

"Code Review Metrics". [0]

"A Large-Scale Study of Programming Languages and Code Quality in Github". [1]

"Software Quality Metrics". [2]

"Study on the Correlations Between Program Metrics and Defect Rate by a Controlled Experiment". [3]

0 - https://www.owasp.org/index.php/Code_Review_Metrics

1 - https://cacm.acm.org/magazines/2017/10/221326-a-large-scale-...

2 - https://www.developer.com/tech/article.php/10923_3644656_2/S...

3 - https://scialert.net/fulltext/?doi=jse.2013.114.120

Re:Clojure is cool by dcu on Sunday September 09, 2018 @11:59AM (#17946458)
I just found this link https://labs.ig.com/static-typing-promise Clojure seems to be the best followed by Go, both designed to be simple
Re:Clojure is cool by hellofunk on Sunday September 09, 2018 @11:52AM (#17946433)
They have been linked many times here on HN over the last 2 years.
Re:Clojure is cool by GuiA on Sunday September 09, 2018 @11:45AM (#17946401)
It would be wonderful if anyone commenting on HN with “studies have found...” would accompany their comment with links to said studies :)
Re:Clojure is cool by AdieuToLogic on Sunday September 09, 2018 @12:22PM (#17946577)
Just did a moment ago in this thread:

https://news.ycombinator.com/item?id=17946568