Top
Best
New

Posted by xeonmc 5 days ago

-2000 Lines of code (2004)(www.folklore.org)
538 points | 245 commentspage 3
rossant 5 days ago|
I think lines of code could be an interesting and valuable metric.

If the lower (negative) score, the better (given a fixed set of features).

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” ― Antoine de Saint-Exupéry, Airman's Odyssey

entuno 5 days ago||
That just encourages bad behaviour in the other direction though. A massive multi-level nested ternary on one line is usually going to be worse than a longer but clearer set of conditions. Trying to make code brief can be good, but it can often result in an unmaintainable and hard to read mess.
windward 5 days ago||
That results in the same AST, it's not really taking anything away
einsteinx2 3 days ago||
Except for readability
sixthDot 5 days ago|||
Halstead complexity ([0]) might interest you. It's a semi-secret sauce based on the count of operators and operands that tells you if your function is "shitty".

[0]: https://en.wikipedia.org/wiki/Halstead_complexity_measures

Cthulhu_ 5 days ago||
You'll never get it right though. Focusing on "features per LOC" means people will write shorthand, convoluted code, pick obscure, compact languages, etc. To use an adage, if a metric becomes a target, it stops being a useful metric.
Kinrany 5 days ago||
An opinionated formatter plus a smart line counter fix this problem. There's still space for abuse but not enough to overshadow genuine improvements.
joseda-hg 4 days ago||
How does a formatter affect me intentionally writing more (or less) lines for the sake of reaching a line count?

print([i * 2 for i in range(10)])

vs

squared_numbers = []

for i in range(10):

    squared_numbers.append(i \* 2)
print(squared_numbers)

It's not even a readability thing, assuming list comprehensions don't bother you they're about equally readable

Kinrany 22 hours ago||
You can write more but you can't write less!
6510 5 days ago||
I often have a mental picture of the thing I need, I start writing it, get a bit "stuck" on architecture and think I could be using a ready made library for this. I find one or a few of them, look at the code (which is obviously more generic) and realize it's many times as large as I thought the entire project should be. With few exceptions the train of thought doesn't even reach the "Do I want to carry this around and baby sit it?" stage. Some how this continues to surprise me every time.

These 5 lines are probably my favorite example.

https://jsfiddle.net/gaby_de_wilde/c8bhcatj/7/

Ensorceled 4 days ago||
We had a VP recommend "lines of code" as part of performance system. I showed some CVS stats of some of our key developers; one of our best performers was at -20K lines of code over 5 years.
Xeoncross 4 days ago||
Would be really interesting if microservices were limited to a manageable amount of code. I wonder if technical leadership has ever guided their org devs that services shouldn't be more than ___ lines of code (excluding tests). Obviously, more services would mean more latency, but I'm pretty sure this one I'm working on now that is over 11k LOC (ignoring comments) could be replicated with a few bash commands.
lpapez 4 days ago|
That sounds even worse honestly.

One of the criticisms of microservices is that factoring a system correctly is already a hard problem, and introducing a network call between them makes it even harder.

Enforcing service LoC limits is equivalent to forcing further factoring of a system, which might not be necessary, especially not into a microservice arch.

Sometimes code is tightly coupled because it needs to be tightly coupled.

insane_dreamer 5 days ago||
When using Claude for production code in my core code base, I'm much more picky about _how_ it's written (as opposed to one-off or peripheral code that just needs to work). I find much of my work involves deleting Claude's code and simplifying its logic. (I'm still not sure I'm saving any time in the end vs writing such code from scratch.)
Scuds 5 days ago||
This being Lisa that's -2000 lines in 68k assembler. That's about as verbose as any real PL can ever get.

For what it's worth, here's quicksort in 5 lines of haskell https://stackoverflow.com/questions/7717691/why-is-the-minim...

kragen 5 days ago||
That's not quicksort, though, because it's not in place; the actual quicksort on that page is in https://stackoverflow.com/a/7833043, which is 11 lines of code. That's still pretty concise. My own preferred concise, or at least terse, presentation of quicksort is http://canonical.org/~kragen/sw/dev3/paperalgo#addtoc_20.

How long would a quicksort (say, of integers) be in 68000 assembly? Maybe 20 lines? My 68000 isn't very good. The real advantage of writing it in Haskell is that it's automatically applicable to anything that's Ord, that is, ordered.

duskwuff 5 days ago||
> How long would a quicksort (say, of integers) be in 68000 assembly?

About 70 lines, once you strip out the comments and blank lines.

https://github.com/historicalsource/supermario/blob/9dd3c4be...

kragen 5 days ago||
This is great, thanks! I was thinking it could be much simpler, but it looks like I was mistaken.

I'm trying to code up a version in ARM assembly to compare, and it looks like it'll be about 30 lines; when I get that working I can compare to see why the difference. In some ways the 68000 is more expressive than ARM, like being able to reference memory directly, even twice in one instruction.

(Am I misunderstanding this, or is this the source code to Apple System 7.1? There seems to have been a mailing list about this codebase from 02018 to 02021: https://lists.ucc.gu.uwa.edu.au/pipermail/cdg5/)

kragen 3 days ago|||
Here's a quicksort in 20 lines of ARM assembly, sorting an array of integers in memory starting at [r0] and ending at [r1] (i.e., inclusive bounds):

    quirks: push {r4, r5, r6, lr}
        4:  subs r2, r0, r1
            bhs 3f                  @ Exit if carry set (no borrow).
            mov r5, r1              @ This frees up r1 as a temp.

            mov r6, r0
            ldr r3, [r5]

        1:  ldr r4, [r5, r2]
            cmp r4, r3         @ Is element at r2 ≤ pivot?
            bgt 2f             @ If so, swap elements at r2 and r6,
            ldr r1, [r6]       @ Load previously first element in > side,
            str r4, [r6], #4   @ and postincrement r6,
            str r1, [r5, r2]   @ and save previous element at end of > side.
        2:  adds r2, #4        @ Increment offset.  Reached the end (>0)?
            ble 1b   @ Loop if ≤ 0 (either N && !V && !C, or !N && V && C)

            subs r1, r6, #8
            bl quirks               @ Recursively sort left partition.

            mov r0, r6
            mov r1, r5
            b 4b                  @ Tail-recursively sort right partition.

        3:  pop {r4, r5, r6, pc}
Fully commented source with Makefile and test C program at http://canonical.org/~kragen/sw/dev3/quicksort.S.
duskwuff 4 days ago|||
> Am I misunderstanding this, or is this the source code to Apple System 7.1?

More or less, yes. It only encompasses the system (i.e. not applications like the Finder) and isn't entirely complete, but it's still a great window into the world of Apple pre-OS X.

> There seems to have been a mailing list about this codebase from 02018 to 02021: https://lists.ucc.gu.uwa.edu.au/pipermail/cdg5/

This mailing list was for a set of projects which focused on taking this code dump (among other things) and making it compile, ideally to reproduce released binaries.

https://github.com/elliotnunn/cdg5

qsort 5 days ago|||
Not true quicksort though :)

That's the problem with comparing lines of code: you're comparing apples and oranges. In this case you aren't even solving the same problem.

sreekotay 5 days ago|||
Are... are you comparing quicksort to... Quickdraw?

Lol - ok that's genuinely funny :). slow clap

meepmorp 5 days ago|||
> For what it's worth, here's quicksort in 5 lines of haskell

QuickDraw was a graphics library, not a sorting algorithm

flohofwoe 5 days ago||
If you think 68k assembler is 'verbose' you haven't seen x86 yet ;)
kaoD 5 days ago||
Code is not an asset, it's a liability.
jarofgreen 4 days ago|
> I'm not sure how the managers reacted to that, but I do know that after a couple more weeks, they stopped asking Bill to fill out the form, and he gladly complied

It would be a much better story if they stopped asking everyone to fill out the form.

More comments...