Live data from Hacker News

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

news.ycombinator.com

41–50 of 216 posts

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

#41
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.

This mentality is how you end up inheriting terrible codebases.

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

#42
Is there any particular language you're looking for? I've found some languages hideous until I understood them and could appreciate their respective graces. Off the top of my head the I can think of a couple of projects you and others may be interested in.

The first is Jones Forth (https://github.com/nornagon/jonesforth), start with jonesforth.S and move into jonesforth.f. I really enjoyed following along with it and trying my hand at making my own stack based language.

The other is Xv6, a teaching operating system from MIT (https://pdos.csail.mit.edu/6.828/2021/xv6.html), not all the code or implementations are top notch but it shows you non-optimized versions (just because they're simple and more readable) of different concepts used in OS design.

If you're interested in the embedded world, there is a really neat project I've been following that feels a more structured and safe (as in fault-tolerant) while still staying pretty simple (both conceptually and in the code itself): Hubris and Humility (https://hubris.oxide.computer/).

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

#43
This is an interesting article on the subject of reading code by the coder and writer Peter Seibel (he also wrote a nice book called Coders at Work with interviews with some programmers who have worked on interesting and widely used software): https://gigamonkeys.com/code-reading/

I’m sure I’ve seen some HN posts about this article, but I can’t remember the content of such.

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

#44
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.

Comes down to semantics, really. Is "good" equivalent to "acceptable" or does it mean "to be strives for"?

Code that works is, usually, acceptable. But code that is acceptable while making no unnecessary maintenance trade-offs is much better. Good code is code that uses standard techniques in standard ways to achieve a result without being verbose or inefficient. But that is a much higher bar than code that is literally good enough.

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

#45
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.

This mentality is how you end up inheriting terrible codebases.

I would rather write “bad” code that lasts long enough to be inherited than write perfect code that sits idle in a repo because I missed the market.

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

#46

This isn't exactly a repo to look at, but the book "Clean Code" is a fantastic read for learning how to write good code. It does have a lot of examples in it, and does a great job explaining everything. https://github.com/jnguyen095/clean-code/blob/master/Clean.C...

There’s so much conflicting advice in this book (like saying functions should be immutable then also saying the ideal function has 0 arguments, apparently mutating the class doesn’t actually make the function mutable to Bob Martin!), and the code examples themselves are horrible (the prime number generator for example).

I’ve heard people say it’s a good book if you just ignore all the bad stuff, but how are you supposed to know what the bad stuff is if you’re a beginner? I think it’s time to stop recommending this.

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

#47
post #45

Earlier quoted context omitted.

This mentality is how you end up inheriting terrible codebases.

I would rather write “bad” code that lasts long enough to be inherited than write perfect code that sits idle in a repo because I missed the market.

Writing good code doesn't necessarily take more effort than writing bad code; in fact, my experience tells me otherwise. Teams that write good code iterate faster.

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

#48
post #34
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.

Good code "is isolated enough that rewriting it won’t cost absurd hours." This is the hard part.

Yes, and it also is the point I think most people here are missing.

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

#49
post #20

This isn't exactly a repo to look at, but the book "Clean Code" is a fantastic read for learning how to write good code. It does have a lot of examples in it, and does a great job explaining everything. https://github.com/jnguyen095/clean-code/blob/master/Clean.C...

https://qntm.org/clean has a great discussion of all the things that are wrong with Clean Code.

I don't like clean code, and like the author I find the things presented in Clean Code to just make incredibly inscrutable code. The worst code bases I have seen have been the ones with no code plans at all, and the ones that use Clean Code and Gang of Four like a bible, both are equally mazes of spaghetti. Clean Code I really just don't agree with, and I think this author lays it out well. Special design patterns and tons of polymorphism usually end up creating multiples of complexity in the effort to reduce DRY at any cost (and often are abstractions that are only ever used one or two times anyways).

Ultimately I think the single most important rule for clean code is: skinny controller, fat model. If you are doing batch data, then this applies still I think. You should have all of the logic you can in the model, avoid data objects. And the code paths that alter things should be as thin as possible. I honestly think it is better to have a 5k line model if it avoids more.

The most unlcean code I have seen usually falls into the abstracted out processes in financial instutitons where they follow Clean Code advice and everything are a bunch of functions passing around some big fat objects full of getters and setters, and changing any functionality means adding changes somewhere in the process to check state and alter the state, which leads to loops and if statements everywhere to see which account type it is at each point etc.

But in OOP programming its supposed to be objects sending messages to each other. Every object should know everything about itself, which is what a fat model demands. Any more abstraction than that seems to get in the way.

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

#50
post #34

Earlier quoted context omitted.

Good code "is isolated enough that rewriting it won’t cost absurd hours." This is the hard part.

Yes, and it also is the point I think most people here are missing.

This is uncharitable. The GP's comment is short. What people have an opinion about is, "Give up on 'good code'" and, "working code, code that pays the bills ... code you can throw away easily, code that you are wholly unattached to".
Post reply on HN