Live data from Hacker News

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

news.ycombinator.com

231–240 of 271 posts

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

#231

It’s not the best, far from it, but it was fascinating to me so I will share. I used to work for a large newspaper. Engineering wasn’t the focus of the business, it was only a means to an end, it was just something they needed to have a competitive website. As a result, the churn rate was very high. But more interesting there was also a very high return rate. Engineers would come and go and return and leave again all…

This is a natural development as the field matures. I've worked in codebases that had roots in the 1980s, and large chunks of code survived virtually unmodified from the 90s. I'm sure some here could tell stories of even older codebases.

Living codebases that have such old roots but have seen gradual maintenance and refactoring such that the whole thing didn't degenerate into spaghetti deserve a lot of respect in my opinion.

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

#232

It’s not the best, far from it, but it was fascinating to me so I will share. I used to work for a large newspaper. Engineering wasn’t the focus of the business, it was only a means to an end, it was just something they needed to have a competitive website. As a result, the churn rate was very high. But more interesting there was also a very high return rate. Engineers would come and go and return and leave again all…

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…

I regularly describe my day job (which consists in reading a 10-year old, arcane & barely readable Spring code base) as me working as a software archeologist. :)

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

#233

My favourite is SerenityOS: https://github.com/SerenityOS/serenity Not only is the code itself structured much more pleasantly than I ever suspected possible in C++, huge parts of it were also recorded while they were being written (see https://www.youtube.com/c/AndreasKling ) so you can see and hear the process that led to the final product. Some of the code is quite gnarly, which is to be expected from a repo conta…

I will second this. I looked into implementing a traceroute utility for Serenity, and went in without any knowledge of the code. I haven't even watched any of the author's videos. But it was so well written that I was able to get a basic version running in a few hours.

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

#235

I will always have a soft spot in my heart for Django, the python web framework, even though I don’t use it anymore. https://www.djangoproject.com/ When I was still learning to code, I spent hours and hours and hours poking around the Django source code. In particular I was fascinated by the metaprogramming used in the Model and Query objects, and I ended up learning a ton about how Python works under the hood.

Me but with Flask and its cohorts like Werkzeug. I always found the amount of security advisories with Django vs that to be something alarming. I might still use it once in a while for something like prototyping. Python is easy to write but writing it "right", in a way that doesn't compromise performance, is a thing.

> Me but with Flask and its cohorts like Werkzeug. I always found the amount of security advisories with Django vs that to be something alarming.

At work, another team introduced automated CVE scanning to fulfill a contractual obligation to do so. When they asked me to implement this on my team's Django project, I said "well alright, as long as it doesn't constantly break the build because of some obscure false positive CVE".

Within a week, the CI job was broken because of 5 "CVE"s. 4 were false positives for our project and 1 was a configuration error by the other team.

Just to let you know to take "number of CVEs" with a large grain of salt.

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

#236
post #9

One of the most surprisingly clear code bases is LLVM. It’s an old complex beast, yet it’s organized beautifully. I mean, it has a lot of essential complexity but little accidental complexity. That’s usually what I strive for when coding. Complexity is sometimes unavoidable, that’s fine, that’s why it’s essential. However, avoidable complexity should be… well… avoided.

This is what I came here to say. it and clang are both good source code.

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

#237
post #67

I had quite some pleasure working with the Source Engine gameplay code. (Some 10 years ago now) https://github.com/ValveSoftware/source-sdk-2013 It is not that the quality of the code is high, but just that it is well organized, and everything seems like it was written by a beginner. That makes it wonderfully easy to read and follow the logic. Since have played around with the Source Engine, I follow the KISS princip…

> and everything seems like it was written by a beginner.

So many developers are afraid of their code being described that way. People are weird.

I'm starting to have the opinion that you shouldn't give software architects the title of software architect because they'll feel as if they're not doing their job if things are simple rather than architecty.

I say that because a software architect is really just a developer with broad scope, but I suspect most of the software architects I know would be offended by that description (I myself hold the title software architect).

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

#238

Earlier quoted context omitted.

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

> We're working on this, albeit slowly. tsserver's implementation predates LSP so it's nontrivial work to move forward in a way that doesn't adversely affect old clients or result in code duplication.

Good to hear you're still committed. By "not a priority" I mean we have been waiting since this was published back in 2016: "[LSP] also means any developer can have a consistent editing experience for their favorite programming language on any tool – even if that tool isn’t VS Code." https://code.visualstudio.com/blogs/2016/06/27/common-langua...

The original bug against Typescript was opened in 2016 as well: https://github.com/microsoft/TypeScript/issues/11274

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

#239

Postgres code is very good, redis as well. Some of the core parts of Linux also totally worth learning from. I also remember how Qt UI code and docs were a revelation after the nightmare of win32 and related frameworks. Bellard's original Tinycc was very entertaining and took a while to digest. Most old and well-maintained projects are worth learning from. Apart from some local tips and tricks what is more important…

Qts documentation is a minefield but their source code is really nice and easy to read.

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

#240

I was responsible for the Turbo C (later Borland C/C++) run-time library in the late 80s and early 90s. Tanj Bennett created our original 8087 floating point emulator. It was real mode, 16-bit code, that kept an 80-bit float in five 16-bit CPU registers as a working value during its internal math calculations. If you ever coded for the PC you will appreciate just how precious register space was on the 8086/8088. It's…

Hi David, thanks for the kind words. I still have the source for that I think, it was written around 1984 originally for a project of my own, then sold to Logitech, Zorland, and Borland (before I went to work for Borland). The Borland one was probably tweaked a bit - like you my memory does not include details.

There were 7 registers to play with. AX, BX, CX, DX, SI, DI, and occasionally BP. MS-DOS had no rules about frame pointer although later Borland would prefer it was kept to a standard use so that exceptions can be handled.

It would have run faster in 32 bit. Many fewer cross products for multiply and faster convergence for division and sqrt, plus just fewer registers needed. But updating the entry and exit code may have been the largest win. By the mid 1990s the FPU was moving onto the CPU chips even at the low end so the main goal would have been stability and backwards compatibility.

I wrote assembly code for many machines before and after that. In the early days such careful juggling of registers was routine. I generally wrote my algorithms in Pascal (later in Modula or Ada and by Borland days, in C++) and then hand compiled down to assembly. That separation of algorithm and coding stopped it getting too tangled.

Thanks for the shout out! These days I write System Verilog (algorithms modelled with C++) for hardware projects, and Julia for the pure software.

Post reply on HN