Live data from Hacker News

Ask HN: What code do you frequently read?

news.ycombinator.com

41–50 of 64 posts

Re: Ask HN: What code do you frequently read?

#42
Website code from the Dev Console / Element Inspector in Chrome.

In terms what I return to, I refer to the LZ algorithm quite often. LZ77 and LZ78 are beautiful in the simplicity and power of their logic. I used to like to look at PRNGs, for example the one in RC4, and hashes. I like the question -- "How do they get so much entropy from so few lines?"

Occasionally I'll look at a one or two line functional programming routine in Python to see about the question, "How can this be done more neatly, elegantly, simply or quickly?"

Algorithms are beautiful, not the code. Code is just worldly forms, which are all an illusion.

Re: Ask HN: What code do you frequently read?

#43
I have this data access library I've been chipping away at for about 7 years now. Started it when .NET 2 was fresh and hip and we were still stuck on .NET 1.1 at work. I really started it because my coworkers couldn't be trusted to dispose of their command and connection objects correctly. But I've kept using it because I keep finding ways to add features to it to make my next project very productive.

So, about once every 6 months I read through it to see if there are any obvious features I can add. Then I read through it to see if there are features I can collapse. It's been interesting to see the features grow linearly, but the code base grow logarithmicaly.

People have asked me why I didn't just use LINQ to SQL or Entity Framework or whatever, but I don't think they understand that A) those things didn't exist at the time, and B) there's something about having a tool that you know inside-out.

Re: Ask HN: What code do you frequently read?

#45
post #19

Golang stdlib is an excellent reference for how to write idiomatic Go code https://github.com/golang/go/tree/master/src

As someone who never learned to code in C, should I be ashamed that I find it difficult to read code with pointers and references?

Re: Ask HN: What code do you frequently read?

#46
post #4
post #3

Usually you don't just go read source code for the heck of it. You read the source code either to contribute a feature or fix a bug. There's no point in reading the src otherwise because you won't find a good enough reason to try to fully understand it.

I beg to differ. For example, reading the Go source is extremely useful both to learn idiomatic Go, and for reference.

It's the only language I've used so far where I feel comfortable going straight to the github source and figuring out how a library works instead of searching stackoverflow. In fact, since I've been writing a lot of code in Go, I've noticed my SO usage has dropped considerably.

Re: Ask HN: What code do you frequently read?

#47
post #11

I pretty much read the code for every dependency I use. It helps me understand how it works and what the docs are fibbing about. If I can't read the code because it's proprietary, I always strace it to see what it's doing. For me, it makes it easier to reason about the behavior of my program. Currently my favorite code to read includes: key/value databases written in C and other "lower level" languages, and the golan…

Would you mind going into detail about how you use strace in that context? Or about how you learned to do that? That's a very handy skill which I need to learn.

Start with htop. You can get that package from apt in a debian-based distro: `sudo apt-get install htop strace`.

When you launch htop, you will see a list of all your running procs. If you select a proc with the arrow keys, you can hit "s" to start a strace and then hit f4 to follow the strace as it dishes output.

This won't work for all procs, you will need root to strace certain procs.

This is a good place to start as it's visual and easy to follow. Later you can start traces from the shell with proc IDs and even get system call info from GDB.

Re: Ask HN: What code do you frequently read?

#49
I read lodash's source to get a feel for how to write fast, high-level, bug-avoiding js. There are a few good ideas in it, like aliasing base methods like 'Array.splice' to a function 'splice' to prevent someone breaking your code by cloberring/overriding these methods.
Post reply on HN