Live data from Hacker News

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

news.ycombinator.com

61–70 of 216 posts

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

#61
I’m hesitant to leave a comment because “good code” almost feels like answering “good food”, but I do have some opinions:

- Ratio of code:documentation INSIDE the source code

- Directory structure depth is “just right”; not too deep nor too shallow

- Number of dependencies is “just right”; don’t build things yourself, but also don’t import the whole world

- TTLD (Time To Local Dev); how simple is the getting started guide in terms of copy-pasta commands + automation + the right amount of context + easy-to-use tooling

- Code culture; follow industry best practices and make it clear where & why you deviate

My personal favorite one: `make todo_list`

We use keywords (TODO, OPTIMIZE, HACK, etc…) through the codebase and make them easily searchable with make helpers.

Ref: https://github.com/pokt-network/pocket/blob/main/Makefile#L5...

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

#63
I'd encourage you to first be opinionated about what you think makes good code. Maybe read some articles or books on it. Don't worry about being right or wrong--someone is definitely going to disagree with you no matter what you think.

And then read any code through that lens. Then read some different code and contrast it. What did you like more or less? What worked and what didn't? Where did it work and where didn't it?

Remember that code that is fantastic is some ways is often horrible in others (e.g. the legendary fast inverse square root).

Approaching it this way helps one consider the reasoning behind what makes certain code good, and forces one to examine the context of the code, which is also critical. And being opinionated helps you remember to apply those rules in the future.

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

#64
post #31

Earlier quoted context omitted.

Taken at face value, this advice is probably just as bad as the opposite ("write perfect extensible modular code with 100% documentation and test coverage"). There is a lot of room in between where the enlightened developer can find happiness.

You misunderstand; nothing about what I suggest says you shouldn’t write, “perfect extensible modular code with dull documentation and tests.” If that’s what you need to do to solve the problem, do that. The point is to stop focusing on the code as the work product, and instead focus on the solution as the work product, of which code is one part.

These are the same thing.

Good code should always solve the solution, to be considered good code. Bad code might solve the solution, it might not.

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

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

[deleted]

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

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

I am a self taught LAMP guy that wrote a mini saas that 34 companies pay for and use. It pays the bills, and works surprisingly fast compared to most CRMs, but I can assure you, it is not good code. Even I'm pissed how shitty I let it get.

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

#70

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

Clean Code is dreadful, or at least the programming examples are.

It was a good book of its time in that it was influential and encouraged people to think more deeply about how to make code readable, but even when it was published I thought it had some terrible advice.

It's probably still just about worth reading, as long as you ignore all the code examples and appreciate that some of the thinking is out of date, and a lot of the rest is controversial at best.

I also find the style grates, as "Uncle Bob" is far too full of himself and e.g. "rips apart" someone's code to produce a worse refactor.

Post reply on HN