Live data from Hacker News

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

news.ycombinator.com

91–100 of 216 posts

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

#91
post #36
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.

"write code that is easy to throw away" is generally a good piece of advice

With the caveat that "easy to throw away" means "easy to understand the implementation front to back so you can know the full impact of throwing it away without crossing your fingers"

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

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

The whole point of the rules in the second paragraph are that you can then fix it without needing to replace the whole thing in one go!

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

#93

One thing to look for are programs that use advanced techniques as opposed to programs that are just simply clear or well-commented. For instance, instead of learning a new programming language, you should learn how programming languages are made. Most of the secrets that computer science majors know that you probably don't were learned in compilers class. (Unfortunately many people are chasing the Holy Grail of "fun…

> Unfortunately many people are chasing the Holy Grail of "functional programming" and never finding it because "functional programming" is a pale shadow of what's possible when you understand how compilers work: this is how Common LISP and scheme are so much more profound then, say, Haskell

Huh? What does this even mean? Both languages are very different from each other and the only thing they really have in common is having functions — how is one more “profound” than the other or any less worthy of being “functional programming”, for whatever that means to you?

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

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

Most people would, I'm sure.

On the other hand, those aren't the only two choices, by a long shot.

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

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

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

#97
post #93

One thing to look for are programs that use advanced techniques as opposed to programs that are just simply clear or well-commented. For instance, instead of learning a new programming language, you should learn how programming languages are made. Most of the secrets that computer science majors know that you probably don't were learned in compilers class. (Unfortunately many people are chasing the Holy Grail of "fun…

> Unfortunately many people are chasing the Holy Grail of "functional programming" and never finding it because "functional programming" is a pale shadow of what's possible when you understand how compilers work: this is how Common LISP and scheme are so much more profound then, say, Haskell Huh? What does this even mean? Both languages are very different from each other and the only thing they really have in common…

I've never seen good code, but if it exists I am sure it'd be a lisp.

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

#98
post #2

Depends what good code is to you. Good code is different depending on your sense of aesthetics, but also it's purpose. Good code for an enterprise-life-blood type of system is terrible code for a "let's check if this is an idea" type of prototype (and vice versa). For a relatively large and mature project, someone might suggest Linux, but it's a bit hardcore in my opinion. FFmpeg is actually really nice, and you can…

I would add to your points. Just read code. When dealing with code you are most of the time going to be dealing with 'good' and 'bad' code. Learn to read both. As both are going to be around. If you just go to 'good code' how do you know what 'bad' looks like? Also to your point what is 'good code' can be very subjective. I have one language I use a decent amount. There is a particular style that many use that they consider 'good code'. I think it is a terrible bit of style to do. I have my reasons for it. But good/bad is not necessarily a metric you can measure.

I would posit that discarding github out of hand is not a great start. Pick one of the big projects on there and follow what is pushed in. You will notice how others interact with the code. You will start to notice who checks in good stuff. Follow them. Also pick your language. As a good style there could be a bad style in another for example C++ vs Python. Python styles in C++ would drive the C++ guys nuts and the other way around.

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

#99
post #93

One thing to look for are programs that use advanced techniques as opposed to programs that are just simply clear or well-commented. For instance, instead of learning a new programming language, you should learn how programming languages are made. Most of the secrets that computer science majors know that you probably don't were learned in compilers class. (Unfortunately many people are chasing the Holy Grail of "fun…

> Unfortunately many people are chasing the Holy Grail of "functional programming" and never finding it because "functional programming" is a pale shadow of what's possible when you understand how compilers work: this is how Common LISP and scheme are so much more profound then, say, Haskell Huh? What does this even mean? Both languages are very different from each other and the only thing they really have in common…

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 with monads than it is with exceptions and they find analogies like "a monad is like a burrito" just get them more confused.

As for something profound I'd point you to

https://github.com/cerner/clara-rules

which many people will struggle with because like many other production rules engines in LISP (and many other examples of simple compilers), there is hardly any code! Contrast that to the orders of magnitude larger rules engine Drools

https://github.com/kiegroup/drools

which is so crazy-complicated primarily because the Drools language is Java-based so you need all sorts of things that Clara or CLIPS don't need. Note that both of these systems use variations of this algorithm

https://en.wikipedia.org/wiki/Rete_algorithm

where a set of rules can be compiled to a network of transitions that can happen when facts are added to the knowledge base so it is very much an example of compiler technology. (That said, Drools supports a lot of features that Clara doesn't and also supports a very advanced RETE-like algorithm that can exploit parallelism that early versions couldn't.)

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

#100

The question doesn't specify any language, so FWIW, I first learned "serious" programming by reading the sources for GNOME Glib, about 18 years ago. https://gitlab.gnome.org/GNOME/glib

And there are definitely some languages to avoid all together if one is trying to learn. I have opinions, but they'll just spark flame wars. Googling worst languages will work.

The fact is someone programming languages - either by design or culture - just encourage unbelievable crap. Obviously, any code can be written well, but if one has to look for a needle in a haystack it's not worth it.

Post reply on HN