Live data from Hacker News

500 Lines or Less (2016)

aosabook.org

11–20 of 45 posts

Re: 500 Lines or Less (2016)

#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 that e.g. I get multiple windows etc. "for free" by just spawning another instance of the frontend which reattaches to the same server.

It's still certainly not 500 lines, but small-ish.

> When you cut requirements you can make things small and easy to understand.

Fully agree with this, and one great way of keeping requirements small like this for me is that I started with the idea that this is my editor. I will only cater to my requirements for the editor itself, but split out shared/reusable functionality in separate libraries so if anyone wants to fork it one day and make their editor we can share much of the code without either of us having to sacrifice.

I think too many people insist that everything they build need to be a "product" that they'll let grow to satisfy as many people as possible even when it'd be better to end up with a dozen smaller, more focused tools.

Re: 500 Lines or Less (2016)

#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?

Re: 500 Lines or Less (2016)

#15
"500 lines" is meaningles without talking into accont its dependencies, that including the SDK.

Corpos will see "500 lines" whatever the dependencies, serious software will embrace the whole software namely with the SDK and dependencies.

Re: 500 Lines or Less (2016)

#16

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.…

The OCR example uses the full capabilities of the browser environment. A quick scan shows html, canvas, events, XmlHTTPRequest, and JSON.parse on the client side. What the python "server" exactly uses isn't completely clear, but it includes numpy, and probably some ANN library. So yeah, it's a bit of a stretch to compare that to 500 lines of stdlib-only C.

Re: 500 Lines or Less (2016)

#17

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.…

Yeah, working in C and python you definitely have to reinvent the wheel less in Python ;-)

I recently wrote an 8bit style CPU simulator (with it's own simple but perfectly usable instruction set) and assembler, together they fit into 1000 lines of C... To be fair that's a fairly specific case where C works really well though!

Re: 500 Lines or Less (2016)

#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 like the idea because it puts emphasis onto a well written documentation which explains concepts while the code is very breve. Shorter code can increase the probability that bugs are found because it is probably more frequently read by other people.

Re: 500 Lines or Less (2016)

#19
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 that the industrial-strength equivalent has a lot more in for use cases, corner cases, and/or optimisations that are not relevant for one's requirements (at least not yet, maybe not ever).

I aspire to write code like that. Useful, concise, but not obtuse. Some of my code is not as significant as those examples, and maybe falls short of my ideals, but it gets a lot done in well under 500 loc. e.g. my website maker in Bash [1] (hot-builds and hot-refreshes without JS), or the JS that drives text art animations for Hanukkah of Data [2].

[1] https://github.com/adityaathalye/shite is about 350 LoC counted this way (excluding the script containing HTML templates).

  $ grep -E -v "^$|\\s?#" bin/{events,metadata,templating,utils,hotreload}.sh | wc -l
  359
[2] https://www.evalapply.org/posts/animate-text-art-javascript/ the text art animator.

  $ grep --count -v -E \
       -e "^$" -e "//" -e "/|\s+\*.*" \
       assets/js/text_artist.js

  213

Re: 500 Lines or Less (2016)

#20
Nice. I borrowed AOSA Volume 2 from a friend a couple of years back.

Too bad the web page performs so poorly on mobile, when two small CSS tweaks would make it fully responsive:

1. Replace `width: 68rem` with `max-width: 68rem` on the body element;

2. Make the flex basis on the table container pixel rather than percentage based.

Post reply on HN