Live data from Hacker News

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

news.ycombinator.com

111–120 of 216 posts

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

#112
post #38
post #27

Earlier quoted context omitted.

I disagree. The problem with believing that "good code" is good enough to deliver business value is short-sighted. Good code is highly maintainable so that you can continue to meet business objectives in a timely manner without regressions. Often this means (ironically) taking a little bit of extra time early on to think about how to make your code readable and "simple enough" for someone else to be able to jump in a…

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

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

#113
Reading code, is second to using it and working with it.

Someone can tell you "This is good code." but good for what? Why is it good?

It is fast code? Is it highly maintainable? Is it well documented and kept up to date? Is it a code that is highly reliable? Is it code that solves and important problem?

My rule of thumb is: Ugly code usually comes from ugly problems. Ugly code can often be some of the most valuable code, because... it does the ugly things! It does what we want 99.9% of the time, using heuristics, and other nasty stuff.

So don't judge code on if it is "good" or not. Judge it on if it does what the author intended, and if it doesn't suck too badly to read with no reason.

Code bases I've worked in and have opinions on:

Samba: Good code base, but you MUST understand the idioms of the codebase, or it is absolutely horrible. It also alas, has the wisdom of 20+ years of existence in it... so it isn't always pretty.

Illumos/OpenSolaris: Nice codebase. Get the SmartOS distribution and you can literally type a few commands and build an entire OS and userland.

FreeBSD: See above. Great codebase, ans also, it can build userland + kernel, though it takes a few more commands. I'll admit I haven't read this one in 20 years. But I always found it a good codebase to work in back when :).

Grab the source for a library you use all the time, you know the useful one but the API feels a bit off... Download it and look at why the API is the way it is.

When looking at code, do NOT neglect looking at the history of a given file or piece of code, it often can teach you quite a bit. :)

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

#114

Earlier quoted context omitted.

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.

What property of the "good code" allows them to iterate faster? Is it because it's perfectly abstracted and encapsulated and SOLID and DRY? Or is it because it's written in a manner, easy to understand, easy to extend, and easy to throw away and rewrite if necessary?

It's abstracted a little bit, but every abstraction is designed to lift a roadblock and reused multiple times like an old tool. And special effort has been spent on avoiding technical debt (hard coded stuff, untested stuff, overloaded or missing properties) to the point of doing things with less effort.

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

#115

Earlier quoted context omitted.

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.

What property of the "good code" allows them to iterate faster? Is it because it's perfectly abstracted and encapsulated and SOLID and DRY? Or is it because it's written in a manner, easy to understand, easy to extend, and easy to throw away and rewrite if necessary?

Everyone's opinion is it's based on the code they actually work with(And devs have lots of personal projects which adds bias, because they think stuff is a good idea just because it works on 1000 line projects)...

I'm guessing solid and dry are a big part, but lack of cleverness, language choice that doesn't require cleverness, and heavy reuse with libraries and frameworks, and choice of feature complete libraries is probably a lot of the speed.

Something in C is going to be more work than JS or Python or Dart and work takes time. Code you write takes more time than code that already exists, unless the code that exists disappears one day.

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

#117

There was a blog post from Peter Seibel recently called [Code Is Not Literature)]( https://gigamonkeys.com/code-reading/ ) which pointed out that although everyone seems to agree reading code is great, very few tend to do it regularly. I feel like I get a lot more out of messing with / hacking on code than I do from reading it. I'm sure people vary, but I've got loads more out of open source contributions to sometime…

Big agree. Tinkering with code to some specific end is gonna teach you a lot more than just scrolling through files, unless you're just curious about the basic architecture or how they implemented some specific thing.

Either way, have a goal in mind when reading code. If nothing else, take notes on what you learn.

Post reply on HN