Live data from Hacker News

Ask HN: Where do I find good code to read?

news.ycombinator.com

161–170 of 216 posts

Re: Ask HN: Where do I find good code to read?

#161
Rust stdlib code is quite high quality although not particularly dense due to large amount of comments. Start from the docs, and click any source link: https://doc.rust-lang.org/std/vec/struct.Vec.html

Sqlite is supposedly high quality C code: https://github.com/smparkes/sqlite

For videos of someone (Casey Muratori) writing video game code and debugging it, Handmade Hero: https://handmadehero.org/

A blog post about how to write code by the same author: https://caseymuratori.com/blog_0015

For how to implement a fairly advanced type system, Typing Haskell in Haskell: https://gist.github.com/chrisdone/0075a16b32bfd4f62b7b

But, honestly, you're probably better off writing code yourself and learning by doing.

Re: Ask HN: Where do I find good code to read?

#163
I think code is less important to read than the design of interfaces / APIs.

I've basically never been blown away by someone's function definitions or whatever, but I regularly run into well designed APIs.

Maybe it's because the API is the thing that has the ergonomics, but the code is just getting things to work. Not sure.

Re: Ask HN: Where do I find good code to read?

#164
>don’t say GitHub

Gitlab, Bitbucket.

I don't really know what to expect. You want to see good production code, and the FOSS community is way way WAY better at this than some of the bubble gum you'd see in a professional setting.

Your question is too general, so I can't exactly give you a specific repository. I could direct you to BGFX[1] for a decent architecture of a cross platform renderer, but if you're not a graphics programmer, that may be a bad exercise, as you'd spend more time learning jargon than studying clean code. Or it uses patterns (or lack of, given graphics programming) that don't apply to your domain.

[1]: https://github.com/bkaradzic/bgfx

Re: Ask HN: Where do I find good code to read?

#165
post #149

Most code is bad, so I think it would help to find some bad code to read

How would that help? You can't invert bad code to get good code.

Most of my job involves reading bad code to understand what it's trying to do before I wedge some nugget of decency in there. The ability to understand the intentions of someone who has no idea how to express what they're trying to do is critical for maintaining other people's software

Re: Ask HN: Where do I find good code to read?

#166
My personal nomination for code you should read next: the source code for Android.

The problem with with "good code" is that it tends to be code that -- more often than not -- is written by people I wouldn't trust to work on real-world large-scale software development.

On the other hand, any sufficiently large project that was successfully delivered necessarily contains almost exclusively "good code", because if it didn't, it would have collapsed under the overbearing weight of "bad code".

What makes the Android source code interesting reading:

- It's written by some of the best software engineers in the business, by any imaginable standard.

- It is an unimaginably successful project.

- It is codes that deals with the gritty enduring reality of programming in the large that cannot reasonably be addressed by toy samples of "good code". That's where real "good code" lives.

- As a programmer, that's the kind of scale I want to work on. Preferably as one of the principle engineers working on Android 1.0. But Android 14 wouldn't be awful.

Overwhelmingly, it is exceptionally good code. Occasionally it is less than happy code. But the places where it are less than happy are almost more interesting than the places where it's good.

The code is 14 years old. It's been through 14 major releases (34 minor releases). It started on phones with 320x200 displays, with megabytes of memory, and processors than could barely run a toaster. And now it runs on phones with 4k displays with 8GB of memory, on processors that are about 2.4 kilo-Crays.

If you're a junior programmer, every single line is better than what you're capable of writing. If you're a senior or intermediate programmer, there is serious food for contemplation. The question that should be asked at every turn: if I was on the Android 1.0 development team, what could I have done to make this happier code?

And I'd really like to see what the "Less code is better code" guru (a recent HN posting) could do with androidx/fragment/app/Fragment.java and friends. A perfect example of a "Good Code Guru" that I would not trust to work on any of my projects.

---

There is no such thing as bad code; but some code is happier than other code.

-- Herbie Hancock.

Or what Herbie Hancock would have said if he were a programmer instead of a jazz musician.

Re: Ask HN: Where do I find good code to read?

#167

Earlier quoted context omitted.

I've met a few young programmers who heard somewhere that object-oriented programming was bad and they want to get the enlightenment of functional programming that they've heard about. Frequently they travel from job to job like itinerant martial artists always looking for somewhere where they practice the true technique but they always seem disappointed as it is just as easy if not easier to screw up handling errors…

What are these iternant code students trying to achieve with all this? Performance? Productivity? Lower defects? Safety critical code seems to still be usually in C/C++, for reasons having nothing to do with the language being safe. Why are these people not studying Erlang, MISRA C, Rust, some kind of formal proof solver language, or OpenCL? What do people aspire to one day work on that would make the Haskell or LISP…

Mastery, perhaps. They see some sort of role model and figure the tools they use are a roadmap to becoming a distinguished engineer themselves. If only it was that easy.

It is interesting how functional programming has to consider data organization completely differently, but sometimes it is just that, a tool or methodology, not a philosophy to subscribe to. Ideally, the good (or future good) engineers realize this and try to understand the less talked about soft skills needed to succeed.

Re: Ask HN: Where do I find good code to read?

#168

Most code is not worth reading. Even well structured codebases are mostly composed of code which is not worth reading. The difference in a well structured codebase is that some of the code prevents you from having to read huge amounts of other code. All code is bad, it starts out bad just by existing, it's only redeeming quality is preventing you from having to deal with more bad code. Everyone thinks they write good…

I don't know, I argue APIs and models are "code" in the informal sense. Architecture is important, but it's even harder to understand "good architecture" than code, not without the architect right there explaining it to you. Many decisions were made for some reason that you can only understand through experience.

Re: Ask HN: Where do I find good code to read?

#169
post #17

Give up on “good code”. Its pursuit is how junior devs pesters senior devs based on a delusion that such a thing is possible. Good code is working code, code that pays the bills. Focus instead on writing code you can throw away easily, code that you are wholly unattached to and is isolated enough that rewriting it won’t cost absurd hours.

>isolated enough that rewriting it won’t cost absurd hours.

I mean, juniors can do this. Once you're a senior, there will inevitably be come coupling you need to make in order to "pay the bills". Or you may make the first part of a system that will be a pain to re-write, even if it's the most elegant, readable code ever.

Nothing wrong with preparation.

Re: Ask HN: Where do I find good code to read?

#170
post #38

Earlier quoted context omitted.

The problem with this “maintainability” argument is the presumption a) that it will be maintained (note I recommended rewriting frequently) or that b) it’s in conflict with meeting business objectives.

Rewriting frequently (reference a) is often out of the hands of the developer because of (reference b) business objectives. Writing code is entirely in the hands of the developer only at the time of writing, not a "henceforth and forever" sort of situation.

And I suppose a dev who only cares about paying the bills would still resonate with this advice. It's not their problem once the suits take charge of the product and give a thumbs up. Why bother with future dev maintenance? the suits will pay for that bride when it burns down, and having that happen is 100x more easy than trying to explain good code upkeep that delays business for a few weeks.
Post reply on HN