Live data from Hacker News

Programs to Read

wiki.c2.com

21–30 of 60 posts

Re: Programs to Read

#21
post #17

I saw the Linux kernel was recommended many times here, but how many people actually read it? Where do you even start? The Linux kernel has around 60,000 files and 25 million lines of code... I think smaller projects are better for learning purposes. If you are interested in reading some smaller projects, check out my project here https://github.com/CodeReaderMe/awesome-code-reading .

Nobody ever wrote a 25MLOC program from start to finish, so I don't think it makes much sense to read it that way. I'd read it the way it was written: from the beginning. What's Linux 0.01 look like? What's the next changeset after that release look like? What was necessary to add the driver for your favorite device? What changes were made for your particular CPU? Programs are not static works (except maybe TeX and M…

Read the early versions, that's exactly what I am doing too!

I read Bitcoin 0.1.5 [1], which only has 15,000LOC and is the first tagged version on Github. Compared with the current Bitcoin codebase with 320,000LOC, it's much less daunting!

[1]: https://github.com/CodeReaderMe/awesome-code-reading/issues/...

Re: Programs to Read

#22
post #17

I saw the Linux kernel was recommended many times here, but how many people actually read it? Where do you even start? The Linux kernel has around 60,000 files and 25 million lines of code... I think smaller projects are better for learning purposes. If you are interested in reading some smaller projects, check out my project here https://github.com/CodeReaderMe/awesome-code-reading .

Nobody ever wrote a 25MLOC program from start to finish, so I don't think it makes much sense to read it that way. I'd read it the way it was written: from the beginning. What's Linux 0.01 look like? What's the next changeset after that release look like? What was necessary to add the driver for your favorite device? What changes were made for your particular CPU? Programs are not static works (except maybe TeX and M…

Have you actually done this? What was your experience?

Re: Programs to Read

#23

I saw the Linux kernel was recommended many times here, but how many people actually read it? Where do you even start? The Linux kernel has around 60,000 files and 25 million lines of code... I think smaller projects are better for learning purposes. If you are interested in reading some smaller projects, check out my project here https://github.com/CodeReaderMe/awesome-code-reading .

The linux kernel has got, conservatively, thousands upon thousands of defects. The only reason to read it is in case you really need to know how it actually works, because the documentation for some syscall is wrong or your systems aren't working right in practice, or you need to know how some undocumented hardware works. Otherwise I'd say it's best left unread.

Re: Programs to Read

#24
> Some are GreatProgramsToRead and some are not

Indeed! It took me a while a appreciate (because it can be painful). Reading bad programs can be very educational, especially when you try to infer the decisions or processes that caused it to be bad in a particular way.

Re: Programs to Read

#25

I saw the Linux kernel was recommended many times here, but how many people actually read it? Where do you even start? The Linux kernel has around 60,000 files and 25 million lines of code... I think smaller projects are better for learning purposes. If you are interested in reading some smaller projects, check out my project here https://github.com/CodeReaderMe/awesome-code-reading .

Most of the kernel code is in the drivers, the general purpose subsystems (VFS, I/O scheduler, task schedulers, memory management etc.) are a small fraction of those 25 million LOC and largely independent of each other so it is not that hard to build some understanding of them.

Some ways you can start:

- Here is start_kernel(), the kernel entry point after booting up and handling the lowest level stuff in asm: https://github.com/torvalds/linux/blob/v4.19/init/main.c#L53...

- grep for SYSCALL_DEFINE to find definitions of syscalls, e.g. this is open(): https://github.com/torvalds/linux/blob/v4.19/fs/open.c#L1076

(understanding how the I/O and networking system calls work is quite helpful for application developers, even if you work in node.js, python or another high level language)

- this is the struct that represents each process in the system, you can pick some interesting field and search for where it is used and where updated: https://github.com/torvalds/linux/blob/v4.19/include/linux/s...

Finally, the linux-insides book is pretty helpful: https://0xax.gitbooks.io/linux-insides/

Re: Programs to Read

#26
Question, where does one start, when planning to read the Linux kernel? There is so much code. I have read it, but randomly. I have read contents of net/ kernel.

I have read the main method where it attempts to launch pid1 of /bin/bash, etc.

Is there a really good place to start reading? For example how does Linux talk to the hard drive?

What's the first thing that happens in the kernel?

Re: Programs to Read

#27
post #2

+ nginx

On the topic of C, I'd also strongly recommend mandoc[1]. It solves a number of hard problems (indexing and searching of man pages, rendering and parsing markup and translating said markup to HTML, PDF and tty output. The code remains fairly accessible. Definitely one of the codebases I regularly refer to for style and practices. [1] https://mandoc.bsd.lv/cgi-bin/cvsweb/

Thanks! :)

Re: Programs to Read

#28
Knuth vs McIlroy's solutions for a Word Frequency programming challenge:

http://www.leancrew.com/all-this/2011/12/more-shell-less-egg...

Knuth's solution has its own elegance and interest including various efficiencies and from-scratch facilities.

McIlroy's will make you wonder how much you're wasting in time and complexity.

Re: Programs to Read

#29
post #17

Earlier quoted context omitted.

Nobody ever wrote a 25MLOC program from start to finish, so I don't think it makes much sense to read it that way. I'd read it the way it was written: from the beginning. What's Linux 0.01 look like? What's the next changeset after that release look like? What was necessary to add the driver for your favorite device? What changes were made for your particular CPU? Programs are not static works (except maybe TeX and M…

Have you actually done this? What was your experience?

Not for Linux, but it's how I approach new programs I have to work on.

I can't decipher this 1000-line function, but it came from somewhere. What did it start out as? That's what the author originally intended it to be. What caused it to grow? That's what features someone else thought it needed.

Re: Programs to Read

#30

Question, where does one start, when planning to read the Linux kernel? There is so much code. I have read it, but randomly. I have read contents of net/ kernel. I have read the main method where it attempts to launch pid1 of /bin/bash, etc. Is there a really good place to start reading? For example how does Linux talk to the hard drive? What's the first thing that happens in the kernel?

Well, some famliarity with the hardware doesn't hurt. Years ago when I studied the Linux kernel myself, I started with qemu, and the gdb stub, and walked line-by-line through the boot process.

But as others suggest, taking an older version, or even simpler unices(xv6,netbsd) might be easier.

Post reply on HN