Hacker News new | ask | show | jobs
by gcanyon 1077 days ago
The answer given is thorough, but somewhat abstract. As a more concrete response, go to projecteuler.net, solve a problem, and go to the discussion board for it.

For most problems:

There will be a ~80 line C solution.

There will be a ~120 line Java solution.

There will be a ~50 line Javascript solution.

There will be a ~40 line Visual Basic solution.

There will be a ~30 line PHP solution.

There will be a ~25 line raw Python solution.

There will be a ~20 line typical Lisp solution.

There will be a ~15 line Python solution using some obscure library.

There will be a ~10 line Lisp solution using some clever hack.

There will be a 1 line J solution.

(other languages omitted, and line estimates are pulled out of my ass)

Whether due to unfamiliarity or genuine opacity, some of the shorter solutions will be incomprehensible to some (most?) people. So while technically more expressive, what good is that if you can't read the solution, let alone write it?

But yeah -- typical line count proxies (inversely) for expressiveness.

4 comments

IMO, the line count is more a function of the "base/standard" libraries as opposed to expressiveness
I don't disagree, the expressiveness of base Python is less than Python + whatever libraries you like.

But the difference in line count between Java + a bunch of libraries and Python + a bunch of libraries is a lot. And the J one-liners rarely involve libraries.

> the difference in line count between Java + a bunch of libraries and Python + a bunch of libraries is a lot

In term of line of code yes, that's correct. But i think this simply shows that "delta in number of line of code" is not a great approximation for expressiveness. The difference between java and python are mainly "ceremonious" line of code that case be generate by any semi-serious IDE. I would put python and java in the same general class of expressiveness (even if python is much more terse).

I think "expressiveness" of languages form a partially ordered lattice, with few language on top.

- Some languages are unilateraly more expressive than other like C++ vs Java

- Most it depends : scheme vs C ; If you are talking about meta-programming and AST manipulation scheme is more expressive. If you are talking accurate memory modeliation and bit manipulation C win.

Since all the languages we're talking about here are Turing-complete, if you don't consider line count or code complexity, then they are all equally "expressive".

So almost by definition we have to look at what is syntactically well-supported, not just "supported at all."

And part of that can be proxied by "I want to do xyz, how many lines of code is that going to take?"

And part of that means that "ceremonious" code isn't excluded, even if a competent IDE can provide it. If um my um comment um includes um a um bunch um of um junk, it doesn't matter if a quick find-and-replace would fix it, it's still annoying cruft that shouldn't be there.

I’ll bring that python solution down to 2 lines with some nested list/dict/set comprehension and lambdas…
Yep, I've seen those.
> Whether due to unfamiliarity or genuine opacity, some of the shorter solutions will be incomprehensible to some (most?) people. So while technically more expressive, what good is that if you can't read the solution, let alone write it?

How many people can read advanced math formulas? Mostly none. So what good is it that they are used?

The answer is, it doesn't really matter if outsiders can't read it. Yes, it increases the hurdle to enter the field, but the benefits drastically outweight the initial learning in the long term.

Same is true (even more so, I would say) for programming languages.

>How many people can read advanced math formulas? Mostly none. So what good is it that they are used? The answer is, it doesn't really matter if outsiders can't read it. Yes, it increases the hurdle to enter the field, but the benefits drastically outweight the initial learning in the long term.

Do they? I feel like a "citation needed" is in order.

There's a target for math formulas, and it's mathematicians. Those can read math formulas, even advanced ones. If outsiders (that is, laymen) can't read them, it's ok: they aren't supposed to be working with math most of the time.

The target for programming languages is programmers. But unlike math formulas, the outsiders that can't read some language J isn't laymen, but still programmers. The problem is not that non-programmer Joe Sixpack can't read J. The problem is that programmers can't read it, or find it unyieldly.

You could argue that, 'that's ok, the target for J is people who comprehend and are productive with something like J'. Sure, but that's precisely what we call out here. That some languages, even though expressive technically, put off not just outsiders from programming, but also programmers.

I don't think every mathematician can read any formula, no matter of the field and how advanced it is.

And for developers it's the same. However, I'll grant that PLs are evolving faster than math does, so there is more catchup-required for sure. But without that there would be much more limited progress. Think lambdas: before they were an "elite feature" and now they are everywhere and languages have adopted them and people had to learn new syntax.

Experts in J say something like, "If you think through the problem, you've solved the problem in J"

I definitely agree that "can outsiders, or even less experienced coders, understand it?" is orthogonal to "expressiveness." I went a little harder than I intended listing that as a drawback to expressiveness, although it's certainly a complementary feature: given two languages of equal expressiveness, the one that encapsulates that range in more comprehensible terms is "better" (there are many other factors to consider, hence the mitigation quotes).

I love the fact that in J:

    mean =: +/%#
Meaning that you can express, from primitives, calculating the mean average with just four characters. And even with my very weak J, that's clear. But then I look at something I wrote over ten years ago:

    candidates =:,/((_4]\4#"3 (_1 + 2 * #:i.2^9) (* &. |:)" 1 _ list)  * (>rowSigns))
and I have zero clue how to interpret that. It's almost certainly not idiomatic J, so it's possible (likely) that it looks like garbage to a J expert as well. Certainly J's terseness doesn't lend itself to commentation. :-)
That's true. After all, in my E-lang I can solve every Project Euler program in under 6 bytes.
Even monopoly odds?