Arc Forumnew | comments | leaders | submitlogin
3 points by thaddeus 4002 days ago | link | parent

Noting the python 2.5 code atop the page I notice, as an example:

   def known_edits2(word):
    return set(e2 for e1 in edits1(word) for e2 in edits1(e1) if e2 in NWORDS)
is on two lines. Where as the arc code puts it on one:

   (def edits2 (word) (dedup:flat (map edits1 (edits1 word))))
I'm just wondering/curious... what determines a line of code ?

I have no doubt the arc code is shorter character wise, but what's to stop me from putting it all on 1 line and being the winner?

2 points by waterhouse 4001 days ago | link

I would say, the code is put into lines naturally--the Arc edits2 definition is short enough that it fits comfortably on one line, while the Python known_edits2 definition probably does not--and then you count up the lines. (I say "probably" because perhaps some people would tolerate lines that long in their code. But I wouldn't, and it seems that neither did the person who wrote it.) What stops you from putting it all on one line and declaring victory? The fact that that's not how humans naturally read or write code; the first thing I'd do when reading such a program would be to separate it back into lines.

Anyway, if you want a more precisely standardizable measure of program length, try token count. That can't be fooled with, either by deleting whitespace or by giving things shorter names. (Though, if you wanted, you could take the program as a string, replace all whitespace with a special character so it's all one token, write a macro that converts the string back into real code, and thus convert an arbitrarily long program into one with a couple dozen tokens. Hmm. Is there any standardized measure of program length that can't be fooled with?)


1 point by thaddeus 4001 days ago | link

> "I would say, the code is put into lines naturally"

I beg to differ. I've being reading pg's code and feel quite comfortable saying that his natural coding would have a line break in the example above - as would any of ours (unless you are unaware of the two spaces required for code on this forum - haha :)

Not a criticism of pg or his code. I think most the submissions to Norvigs site contain code where people are removing "natural" line breaks.

As an example..... Quote from comment on page:

  "Perhaps we should stop at 15 lines before we start getting unreadable code :) !"
speaks the truth.

I don't think there's any real value in creating a table ranking languages by line numbers. I do think the code pg produced does demonstrate how pleasant arc is to read while being very short.


3 points by pg 3998 days ago | link

I broke lines that would have been more than 80 characters.