Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Good code to read for a beginner
4 points by greggyb on Jan 20, 2015 | hide | past | favorite | 14 comments
Multiple sources (e.g. Eric Raymond's "How to Become a Hacker"[0]) suggest reading others' code as a learning exercise when beginning programming, to get a feel for good style.

It seems a bit of a catch-22 though, as I don't believe myself (or any other beginning programmer) to be able to discern worthwhile code for review.

That understanding in place, what are some of your suggestions for good code to read to get a feel for style and technique?

Note: I am working through MIT's OCW CS material (still pretty beginner), and have picked up a pretty decent smattering of Python and Scheme thus far. These languages (including Common Lisp - I recognize that there are large differences between Scheme and CL, but I think I should be able to get the basics) would be most useful for me as I already have a pretty good foundation in them, but don't hesitate to suggest good programs in other languages, as I will need to learn more at some point, and hopefully others will find this thread useful.

[0]http://www.catb.org/~esr/faqs/hacker-howto.html#skills1



My $.02, when I started programming I tried the same thing by buying a book where a guy explained game programming by taking you through steps to write an entire game he made. It made me want to quit programming. I found looking at small algorithms a lot more helpful. A good source for those is to read code of sorting algorithms and data structures. Then try to build them yourself (e.g., read the source code for a linked list, then build a circular linked list).

I don't see the need to worry about style if you're a beginner.


Thanks for your input.

Do you have any recommendations for a starting point for any of these algorithms. My first shot would probably just be trawling Wikipedia, but if there's a better place to look I'm all ears.


I didn't have any resources in mind when I wrote that, but after a brief search, I think this wiki looks good:

http://rosettacode.org/wiki/Sorting_algorithms

http://rosettacode.org/wiki/Category:Data_Structures

Once you're at an intermediate level in any language and experienced with programming concepts in general, then it does make sense to develop good coding style (by reading books and blogs about the topic) and adopt idiomatic practices of the community (if they're sane). But simply reading a large codebase to become a better programmer is drinking from a firehose. It might make sense for an experienced programmer, but usually you'll do that because you're working on the codebase.


Thanks very much for your feedback. This is helpful for me.


If you're into web dev, the annotated source to Backbone / Underscore are interesting reading:

http://underscorejs.org/docs/underscore.html

http://backbonejs.org/docs/backbone.html


Thanks very much.


It may be difficult for a beginner, but try to read and understand Tornado and Flask's code. (They are written in Python)


Thanks for the suggestion.


I would just pick a popular library in your language of choice.

It'll probably have some great code and some rough edges. It's okay. Learn how to get shit done and learn elegance, too.

Or you could pick a common theme and look at various implementations of it. Look at twitter api libraries and see how they differ, perhaps?


Thanks for the suggestion.


Check out the practical chapters from Practical Common Lisp.

http://www.gigamonkeys.com/book/


Thanks for your feedback. It's difficult to determine which books are worth my while up front.



Thanks for your feedback. I've actually completed the vast majority of LPTHW, and it was a great foundation, but I feel like there's a bit of a jump from how to do basics and how to turn that into good code. I still have to finish off the testing chapter and beyond so maybe it comes back around.

I feel like there's a gap between "Here's looping, conditionals, IO, OO basics, functions, etc..." and being able to write something useful. Everywhere I look seems to fill the gap by saying "Go read code" or "Hack on things you use". I'm trying to answer the first part here, and the latter leads me to very large programs that I can't really digest yet.

I've worked on a couple simple programs for myself, but typically end up thinking about how trivially I could implement it on an RDBMS (I work in BI consulting - I write SQL for half of my work), but understanding that that would be overkill. E.g. I'm working on a simple task tracking program that captures basic metadata that would be useful in capturing billable hours. I could write up a basic schema and some stored procedures in a few hours, but then I'd just be punting all the hard stuff to the DB and not improving.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: