Live data from Hacker News

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

news.ycombinator.com

181–190 of 216 posts

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

#181
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 throws away years of accumulated edge cases handling. Suddenly the thing doesn't work because one particular model of printer needs an undocumented command to enable some feature, or users are inputting bad data because you forgot the checks you accumulated... Seems not ideal for end users, unless you're working with microservices or something with well defined specifications that people are actually paying…

Rewriting does not need to be an all-or-nothing endeavor.

If you design your app as a collection of subsystems, it's sometimes faster to destroy and rebuild one of them than it is to refactor.

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

#184

Earlier quoted context omitted.

"maintainable" code is disposable. Modern web stacks are built on the idea that you can delete a file and re-implement its interface with a different service behind it later on. Instead of writing code which will be easy to modify, write a good interface which solves your problems in a way that's easy to reason about, and feel free to write garbage implementations that will get "refactored" (thrown away) every year o…

You can write good code behind well defined interfaces, too. There's no reason you have to pick one or the other. Bad implementations are still bad.

I usually find it faster to define a good interface, hack together and implementation, then rewrite it.

A good interface limits the blast radius of my refactor.

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

#186

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.

There's definitely a code component to them, but most of reading about and understanding them would come from reading the surrounding documentation or reasoning. Most of that text would be prose, rather than a language consumed by any computer system.

I'm not sure what you mean by "understand good architecture." One thing that makes an architecture good is its simplicity and clarity. If it's hard to understand, it can't be that good. I can say for certain: if you understand the problem being solved but not the architecture, then it is for sure a bad architecture.

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

#187
post #35

Earlier quoted context omitted.

> 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 highly maintainable so that you can continue to meet business objectives in a timely manner without regressions. I think you essentially agree on what people should do, regardless of whether you call this 'good code' or just maintainable cod…

> Don't copy and paste the same implementation x times because that way there's only one place to fix it. But also sometimes it makes more sense to copy and paste over trying to fit an abstraction where it shouldn't be. :) I think the purpose of questions like the ones by OP is not to figure out "rules" (which are useful only for beginners) but to figure out where and why rules were broken. Sometimes (often) the answ…

> But also sometimes it makes more sense to copy and paste over trying to fit an abstraction where it shouldn't be. :)

I find that's a smell of limited languages: Maybe a language has poor error handling semantics, maybe it's not expressive enough to make a parameter generic.

It can also be a smell of not understanding the language well enough, too. Maybe there is no need to copy and paste, but the programmer didn't understand the language well enough to make a generic abstraction.

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

#188

I really like the go standard library. It's all really clear and easy to understand https://cs.opensource.google/go/go/+/refs/tags/go1.21.0:src/... https://cs.opensource.google/go/go/+/refs/tags/go1.21.0:src/...

It's worth noting, Go's stdlib isn't perfect, but that's part of why it's so good. You can see how they've deprecated certain methods/fields/etc while maintaining backwards compatibility.
Post reply on HN