4 ms·
500 Lines or Less (2016)
- revskill 3y agoWhat about useless program ?
- jlnho 3y agoI can write useless programs in 0 lines!
- beardyw 3y agoWell, I have done that in order to see what the compiler creates which isn't your program. Quite useful!
- lpapez 3y agoI can tell you I wrote many useless things with more than 500 lines, also known as "enterprise software".
- egeozcan 3y agoI could write a fairly useless program with nearly half the amount of lines!!: https://github.com/egeozcan/gifDisco https://github.com/egeozcan/gifDisco Being able to write silly stuff because you can is immensely satisfying.
- hnfong 3y agoFor that you can go savor the archives of IOCCC : https://www.ioccc.org/ https://www.ioccc.org/
- hedora 3y agoThe probability that a program is useful given the number of lines probably peaks in the 10,000’s-100,000’s.
- Gormisdomai 3y agoGlad to see this on here again. This book is what bridged the gap between my undergrad degree and feeling like I could contribute to nontrivial real software projects. I originally found it because of HN
- spandextwins 3y agoAll my programs are one-liners.
- Culonavirus 3y agoHmm. 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. 500 lines of java server app. 500 lines of c# .net desktop app. 500 lines of electron javacript code. When I imagine the amount of a "useful program" I can write in 500 lines of C (or other low level statically typed language) while using minimal amounts of library code versus the "useful program" I can write in 500 lines of Javascript while using maximum amounts of Electron library code (i.e. all the functionality of chromium + node + electron), the difference is staggering ( try writing a cross platform video player in C vs Electron.. ). That doesn't mean Electron is better, especially if you need maximum resource budget usage or maximum control. It's never about the number of lines, it's how you use them ;)
- tgv 3y agoThe 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.
- jhonsrid 3y agoYeah, 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!
- ktpsns 3y agoI 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.
- vitiral 3y agoOne 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 cut requirements you can make things small and easy to understand. I'm only concerned about big-O and keeping things simple :) http://github.com/civboot/civlua http://github.com/civboot/civlua
- vidarh 3y ago> 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.
- vitiral 3y agoAnything 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.
- sylware 3y ago"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.
- jdjdjdhhd 3y agoExactly... Given the right library I could write a one line program that does the same as a 500 lines program
- sylware 3y agoYep, all that "line" thingy is meaningless, and it is even worse when you are serious enough to consider the life cycle of many pieces of software (does not work with all software). From a life cycle (and more) perspective, it can be very "better" to write some software with 1000 lines with less deps than 10 with more deps...
- adityaathalye 3y agoBookmarked! 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 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/ 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
- eternityforest 3y agoI 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.
- depressedpanda 3y agoNice. 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.
- dang 3y agoRelated: 500 Lines or Less - https://news.ycombinator.com/item?id=12170182 https://news.ycombinator.com/item?id=12170182 - July 2016 (19 comments) 500 Lines or Less - https://news.ycombinator.com/item?id=11796253 https://news.ycombinator.com/item?id=11796253 - May 2016 (61 comments)
- dingosity 3y agoThis seems cool and all, and I seldom critique web page design because... hey... I've developed some very crappy looking web pages. But... the designer of this page made it's width wider than a typical desktop browser window and much wider than a typical mobile phone. I turned my 10" tablet into landscape mode and it was still wider than would fit on the screen without scrolling. I know all the cool kids are doing this, because it's only old people who care about the ease of reading things on the web. But... please... don't do stupid things like this. That being said, it's easy enough to open dev tools and unclick the ``width: 68rem;`` clause or open it in lynx which replaces the web designer's styling stupidity with its own, more consistent styling stupidity. The content wasn't that bad.