Live data from Hacker News

500 Lines or Less (2016)

aosabook.org

21–30 of 45 posts

Re: 500 Lines or Less (2016)

#21
post #14
post #10

One of my goals is to rewrite all software for developing software, with each application at about (or less than) this sweet spot. Database, version control, runtime type system (Lua), proto-like serialization, code refactoring, parsing library... The list goes on. About the only heavy thing will be the text editor, and I'm still keeping that at a few thousand lines (+ a small core data structure library). When you c…

You want to write a serious database in 500 lines. Honestly, I'd be impressed but it's a hell of a target. Err, how long are your lines going to be?

Normal lines (max 80) but I do prefer having each line do "one full thought", like putting `if then ... end` on a single line (if it fits)

I wrote about the database here

https://github.com/civboot/civboot/blob/main/blog/0012-dev-l...

Re: 500 Lines or Less (2016)

#22
post #12
post #10

One of my goals is to rewrite all software for developing software, with each application at about (or less than) this sweet spot. Database, version control, runtime type system (Lua), proto-like serialization, code refactoring, parsing library... The list goes on. About the only heavy thing will be the text editor, and I'm still keeping that at a few thousand lines (+ a small core data structure library). When you c…

> About the only heavy thing will be the text editor, and I'm still keeping that at a few thousand lines (+ a small core data structure library). What I found to work really well to trim down my own text-editor was a combination of externalising all menus etc.. E.g. opening files, selecting themes, selecting buffers, all call out to scripts using rofi or similar to do the actual selection, and going client-server so…

Anything that can be shared or tested individually gets moved to a library, no matter how small.

I'll have an 'ed' library for things like the gap buffer and undo/redo aware buffer (built on gap) as well as the movement logic and stuff like that.

The "editor" will only handle default bindings, the action/draw/paint cycle and an action event loop. These are core to the specific application so they belong to be coupled to it.

Re: 500 Lines or Less (2016)

#23

Hmm. I get the sentiment (500, i.e. not too short, not too long), but 500 lines will mean different things for different people and different programming stacks. It literally can mean 50000 vs 500 "lines of knowledge" required. I'm not sure why would you name your book like that. Consider: 500 lines of defensively written web server C++ code. 500 lines of C driver code. 500 lines of assembly. 500 lines of php script.…

Remembering that a line of code is a price you pay, and not an accomplishment in and of itself, is a valuable mindset to maintain. And I think that 500 lines is a comparable volume of code to digest across many languages. It may accomplish varying amounts of useful work, but that's beside the point. The purpose of this work is not to engage in an inter-language, inter-domain pissing match; it's to meditate on the human economics of software design. It says as much in the introduction: "500 Lines or Less focuses on the design decisions that programmers make in the small."

Thinking about these things does matter. This past week I refactored a somewhat challenging piece of code my team had been maintaining from several hundred lines of code to about 30, without playing code golf. And I found and removed bugs (and even a little bit of code golf) in the process. Similar to what the book's introduction suggests, a lot of this change was down to rethinking the abstractions and decomposition of the code. The original version apparently tried to force the problem to fit a preselected design pattern. Doing that instead of decomposing the problem according to its own natural structure really does seem to have resulted in a ~10X code bloat factor.

Re: 500 Lines or Less (2016)

#24

Hmm. I get the sentiment (500, i.e. not too short, not too long), but 500 lines will mean different things for different people and different programming stacks. It literally can mean 50000 vs 500 "lines of knowledge" required. I'm not sure why would you name your book like that. Consider: 500 lines of defensively written web server C++ code. 500 lines of C driver code. 500 lines of assembly. 500 lines of php script.…

That's literally the point of the book. Showing how you can use 500 lines of codes to do a whole lot of things, if you know what you're doing and use the appropriate language, in a way that others can still understand what's going on.

Pick the tool based on your requirements, not the other way around =)

Re: 500 Lines or Less (2016)

#25

Bookmarked! These look like amazing study projects; the kind one can copy and learn from. Quite like how they do it in art school. Each one of them looks like it solves a nontrivial problem, and edifies the reader on the basic contours/tenets of the problem/solution space. I love this kind of stuff, because it shows one _can_ solve a pretty juicy problem with not that much code, honestly. Also because it suggests tha…

I think they're great for study and as art, but I don't really aspire to write programs like that.

In fact most of the time I don't aspire to write anything at all. If I need a feature my first thought is "Does an existing project want this added or a plugin that does it, it does something already have it that just needs cleanup and bugfixes?"

I might not always need the industrial strength equivalent, but analyzing whether I do or not takes time, and using the "just enough" approach can create fragmentation and require learning a new tool for every project, instead of focusing on one that you trust will be maintained for a while.

I do value performance, but sometimes optimization gives better performance than simplicity.

Re: 500 Lines or Less (2016)

#26
post #10

One of my goals is to rewrite all software for developing software, with each application at about (or less than) this sweet spot. Database, version control, runtime type system (Lua), proto-like serialization, code refactoring, parsing library... The list goes on. About the only heavy thing will be the text editor, and I'm still keeping that at a few thousand lines (+ a small core data structure library). When you c…

Arthur Whitney had a whole operating system, kOS, in a few hundred lines iirc (including bare metal storage drivers, screen drivers, file system and more), with a more-than-sql database in 200 lines and an editor in a few tens.

The magic — other than Arthur’s genius - was the programming language K (also designed and implemented by Arthur).

And from another direction, the STEPS project from Alan Kay did a metal-to-everything in 20K lines, including IIRC a paint program and word processor. They only counted lines you need to understand - e.g., it parses the TCP spec RFC to get all the structures and constants; the spec parser is included in the 20K count, but the TCP docs and the generated TCP code is not.

Re: 500 Lines or Less (2016)

#27
post #21
post #14

Earlier quoted context omitted.

You want to write a serious database in 500 lines. Honestly, I'd be impressed but it's a hell of a target. Err, how long are your lines going to be?

Normal lines (max 80) but I do prefer having each line do "one full thought", like putting `if then ... end` on a single line (if it fits) I wrote about the database here https://github.com/civboot/civboot/blob/main/blog/0012-dev-l...

Woof. Man, I really don't think you understand what goes into a DB if you think you can do D in 500 or even 5000 lines, unless maybe, maybe, you're aiming for something so simple it's merely a toy.

Re: 500 Lines or Less (2016)

#28
post #10

One of my goals is to rewrite all software for developing software, with each application at about (or less than) this sweet spot. Database, version control, runtime type system (Lua), proto-like serialization, code refactoring, parsing library... The list goes on. About the only heavy thing will be the text editor, and I'm still keeping that at a few thousand lines (+ a small core data structure library). When you c…

Re the text editor, when I was writing an editor for my homemade CPU I used the one from this tutorial: https://viewsourcecode.org/snaptoken/kilo/index.html - it is 1000 lines of C. Might be useful to you.

I have diverged a bit from the tutorial because I didn't want syntax highlighting, I really wanted vi-style keybindings, and my environment is much more performance-constrained. Mine is at https://github.com/jes/scamp-cpu/blob/master/sys/kilo.sl (in my made-up programming language).

Re: 500 Lines or Less (2016)

#29
post #18

Hmm. I get the sentiment (500, i.e. not too short, not too long), but 500 lines will mean different things for different people and different programming stacks. It literally can mean 50000 vs 500 "lines of knowledge" required. I'm not sure why would you name your book like that. Consider: 500 lines of defensively written web server C++ code. 500 lines of C driver code. 500 lines of assembly. 500 lines of php script.…

I must formally disagree: 500 lines is about how you can read and comprehend a program. 500 lines fits in a single file in virtually any programming language (yes, you can put multiple classes in a single *.java file). And if you make use of libraries which allow to write 500 lines of high order instructions steering a vastly complex machinery, even better! This allows the 500 lines to be very expressive. I really li…

> 500 lines is about how you can read and comprehend a program.

(With the exception of languages that are idiomatically horizontal, such as Forth or APL, where a 500-line program sounds about as reassuring as a 500-line mathematics paper, and is probably about as dense. But none of the programs in that book use one of those.)

Re: 500 Lines or Less (2016)

#30
post #26
post #10

One of my goals is to rewrite all software for developing software, with each application at about (or less than) this sweet spot. Database, version control, runtime type system (Lua), proto-like serialization, code refactoring, parsing library... The list goes on. About the only heavy thing will be the text editor, and I'm still keeping that at a few thousand lines (+ a small core data structure library). When you c…

Arthur Whitney had a whole operating system, kOS, in a few hundred lines iirc (including bare metal storage drivers, screen drivers, file system and more), with a more-than-sql database in 200 lines and an editor in a few tens. The magic — other than Arthur’s genius - was the programming language K (also designed and implemented by Arthur). And from another direction, the STEPS project from Alan Kay did a metal-to-ev…

Totally love the quest for elegant and minimal implementations. But I don't think line-counts are comparable across languages. The APL/K crowd has a very different opinion on the number of statements per line.

To give an impression of the style, this is the C-implementation of a K interpreter. Have fun deciphering that.

https://codeberg.org/ngn/k/src/branch/master/a.c

Post reply on HN