Live data from Hacker News

Ask HN: What's the best source code you've read?

news.ycombinator.com

191–200 of 271 posts

Re: Ask HN: What's the best source code you've read?

#191
post #179
post #56

Nobody has mentioned Knuth’s corpus of work in Pascal-Web for the TeX ecosystem. This is code written for an era where there wasn’t an ecosystem of libraries for common tasks and even things like being able to access a file in random access order couldn’t be counted on. Even 7-bit ASCII couldn’t be counted on as a given (EBCDIC-based IBM mainframes were a significant element of the computing landscape still). Against…

I think LSP language server protocol and literate programming are a match made in heaven. A simple syntax like noweb and a LSP dispatcher which only handles the noweb syntax elements and dispatches both text and code chunks to respective back ends; the LP LSP Server tangles the code chunks and presents the tangled code to the code specific LSP servers and does the mapping forth and back of the position-in-nw vs posit…

Speaking anecdotally, I have nothing but issues with LSP. It's a pain to use, a pain to configure, gives sub-par results and is usually wraps with extra "features" that change how code gets edited between different languages (I know this is less LSP's fault).

Not to dismiss the mountain of work people have put into it, but it feels very hacked together and clunky rather than a shining achievement.

Re: Ask HN: What's the best source code you've read?

#192
post #189

Since TeX and LLVM were already mentioned, I will casually mention the comments in Laravel's codebase which are all three lines long with each line exactly three characters shorter than the previous line. The art of computer programming at work. Example (config file, but the entire codebase is like that): https://imgur.com/UnIUZmZ

Honestly...neurotic and counterproductive. You have to add too much useless words to make it fit. Most of these comments could be much shorter and easier to read. Also too much separators and whitespace around those comments.

Opinions differ. I personally like it, but I don't think I would manage do it in a reasonable large codebase. Still, I agree with the points brought up in the Reddit discussion on the topic (https://www.reddit.com/r/laravel/comments/20ovey/just_notice...), in particluar:

  I think it's awesome and I'm trying to do this too. It is a great trick that forces you 
  to re-read your comments and be as clear as you can. Also, you take the time to find 
  synonyms and look for typos. Overall it's a great way to learn how to be thorough.

Re: Ask HN: What's the best source code you've read?

#193

Earlier quoted context omitted.

That’s absolutely not true. Bitcoin the app is often mixing several layers of abstractions and several usage patterns together. Is it for actually keeping track of money? Is it for APIs? is it for end users, or for servers? Is it CLI or a GUI app? And it’s in C++, which is almost never readable. And of course they have their weird names for everything (all the ScriptSigs etc), and the OP script which is at the same t…

Yes, I would second this. It's hard to rewrite, but needs it in many places that I've read (in particular, the code to detect BIP9 etc soft fork activation is horrible). To be fair, the slow polishing of a thousand hands continues. libsecp256k1 is tested to a level few if any FOSS libraries achieve, for example.

Yeah, the test suite is very very thorough.

Re: Ask HN: What's the best source code you've read?

#194

Earlier quoted context omitted.

The book "A Deepness in the Sky" features people living on an ship whose operating system is thousands of years old. One of the main characters is considered a software archaeologist of sorts - he's an engineer, but in a sense also a historical researcher. I can't emphasize enough that this notion is only a side point in the story and not a main aspect of the plot, sadly, so I wouldn't go reading it in hopes of heari…

The "software archeologist" idea has lived rent free in my head ever since I read the novel nearly twenty years ago. It's an absolutely fascinating premise, one I can most definitely see being viable to grow into a fully-fledged novel. I would definitely read that.

We're half-way there already. I've been telling people that the volume of software written has exploded exponentially, and the real skill anyone in IT has now is not knowing how to use a piece of software on a computer, but simply knowing that a piece of software exists to solve a problem.

These days I work largely in a cloud / devops role, and I can't even begin to list everything that I ought to be using but can't because there aren't enough hours in the day to keep up with all of the new developments. That's within a single language, a single web framework, and a single cloud provider!

I see projects where architecture astronauts stitch together multiple clouds, multiple languages, and some random junk on-prem that was installed over a decade ago by someone who has passed away since then. Within the expected lifetime of such a system, you'll need a software archaeologist to figure it out!

Re: Ask HN: What's the best source code you've read?

#195

Earlier quoted context omitted.

What about this https://observablehq.com/@tomlarkworthy/redis-backend-1

The same thing. I don’t see chunk reuse, nor the ability to generate standalone documentation or export the code to files. Have you seen actual literate programming documents? The Noweb tool’s page has examples.

Sounds like nbdev which indeed exports code and documentation from a single notebook, plus unit tests for external execution.

Re: Ask HN: What's the best source code you've read?

#196
The standard library of Julia, especially with the possibility to just enter `@code someFunction(params)` in the REPL to see the source of the method that the call would be dispatched to, the source can basically function as a second layer of documentation (the first layer being docstrings that are part of the source as well, but are usually accessed either via the IDE, or the help-mdoe of the REPL).

Re: Ask HN: What's the best source code you've read?

#197
post #191
post #179

Earlier quoted context omitted.

I think LSP language server protocol and literate programming are a match made in heaven. A simple syntax like noweb and a LSP dispatcher which only handles the noweb syntax elements and dispatches both text and code chunks to respective back ends; the LP LSP Server tangles the code chunks and presents the tangled code to the code specific LSP servers and does the mapping forth and back of the position-in-nw vs posit…

Speaking anecdotally, I have nothing but issues with LSP. It's a pain to use, a pain to configure, gives sub-par results and is usually wraps with extra "features" that change how code gets edited between different languages (I know this is less LSP's fault). Not to dismiss the mountain of work people have put into it, but it feels very hacked together and clunky rather than a shining achievement.

Case in point, Microsoft develops an editor (VSCode) and LSP so that N*M language integrations wouldn't be necessary. But in the development of their language (TypeScript), LSP support is not a priority (in part because LSP is inadequate in its current form): https://github.com/microsoft/TypeScript/issues/39459

Re: Ask HN: What's the best source code you've read?

#198
post #181
post #71

I haven’t read all of it, but the Principia source code has a comprehensive units system and makes effective use of Unicode: https://github.com/mockingbirdnest/Principia/ https://github.com/mockingbirdnest/Principia/blob/master/ast... is a decent example of both: // We compute the mean rate (slope) of the mean anomaly M(t), the mean // argument of latitude u(t), and the longitude of the ascending node Ω(t). … Product…

lovely. it's 2022 and I see unknown-glyph-boxes on my up to date smartphone... I love the use of mathematical glyphs in math code, too, much more readable, _if_ it's readable. sigh.

The problem is (apparently) no monospace version of the /ʃ/ character, which renders fine in non-monospaced fonts (on Android).

Re: Ask HN: What's the best source code you've read?

#199
post #73

Not exactly source code, but the https://frinklang.org/frinkdata/units.txt is the most fascinating configuration file I've ever read. It is also the only one that I occasionally re-read just to enjoy the commentary on the standards organizations that are responsible for some of the complexity.

This is pure brilliance. The depth of reasearch they went to for some of the units is mind-boggling

--- start quote ---

    /*  From Department of the Army's authoritative study: "Effects of
        Nuclear Weapons", footnote 3 to section 1.45, available at:
        http://www.fourmilab.ch/etexts/www/effects/

       "The majority of the experimental and theoretical values of the
       explosive energy released by TNT range from 900 to 1,100 calories per
       gram.  At one time, there was some uncertainty as to whether the term
       "kiloton" of TNT referred to a short kiloton (2 x 10^6 pounds), a
       metric kiloton (2.205 x 10^6 pounds), or a long kiloton (2.24 x 10^6
       pounds).  In order to avoid ambiguity, it was agreed that the term
       "kiloton" would refer to the release of 10^12 calories of explosive
       energy.  This is equivalent to 1 short kiloton of TNT if the energy
       release is 1,102 calories per gram or to 1 long kiloton if the energy
       is 984 calories per gram of TNT."

       So, evidently they don't quite specify which ton is required...
--- end quote ---

And it goes on

Re: Ask HN: What's the best source code you've read?

#200
Maybe I've just been exclusively working on really boring stuff, but there are no examples that particularly come to mind.

There are programs and programmers that impress me, and once in a while I'll come across an interesting algorithm, but I can't really think of any code that is anything more than just code.

It's either too simple to do anything I'm interested in, too full of ugly hacks like most large programs, or deals with math and algorithms way above my understanding, to the point where I probably haven't even tried to read it.

Some of most memorable bits or code for me are the examples for frameworks and libraries, but those are more impressive for the code that isn't there, rather than the code that is.

I love declarative work(Not so much pure functional, but things like CSS and CAD constraints where a solver figures out how to make your intent happen) but again, that's notable for the code that isn't there.

I also really like hardware workarounds. It's so cool to be able to have software that runs fine on bad hardware. It's not that common, but occasionally you can pull it off in a reliable way that really is just as effective as using better hardware. Seeing pure code replace hardware is kind of like a further development of replacing mechanical stuff with solid state chips.

I really just don't care about code itself very much. I don't want to write bad code, but I only care about good code in as much as it will actually benefit the project. Once it's good enough, features or architecture improvements or unit tests or something might be more important, and interesting or clever code might bring the project down.

If I'm reading your code, I'm probably either adding to it and complaining that it doesn't have an API hook already there, or fixing a bug.

If I'm using but not reading your code I'm probably happily assuming it's great, if it's a popular trusted thing.

Post reply on HN