Source code reading list

D

David Delony

Since the best way to learn how to program well is to read other
people's programs, which open source projects written in C stand out
as examples of well-written code?
 
M

Malcolm McLean

David Delony said:
Since the best way to learn how to program well is to read other
people's programs, which open source projects written in C stand out
as examples of well-written code?
It really isn't.
You should read other people's code of course, but there are all sorts of
reasons why reading working "real" programs won't tell you how to do a good
job yourself.
Think of a program as a building. Not a house. A functional building like a
factory that has to be built to budget and always has some special
requirements. Normally the procedure will be to buy in a lot of pre-formed
components - walls, stairs, roofs and so on. Then they are bolted together.
But because our factory is a real building housing a unique process, some
will have to be modified. You might need air flow towards the "dirty end",
so you've got to seal all the windows, take out all the firedoors, and put
in fans, for instance. Then because you've taken out the firedoors you might
need to put in a sprinkler system to comply with regulations. So we end up
with a lot of standard components, modified components, and some custom
built components, all welded together and then put under a facade to make up
a finshed building.

To really understand how to make a building like that youself, it is best to
go to the standard components. The finished building will often confuse.
Code, such as mass of defines to make a file compile under both Windows and
Unix, can be well-written in the sense that it achieves the goal, whilst
being very hard for a human to understand and not a good basis for other
code, often not even a good basis for another cross-platform program. Often
there will be bits which have been micro-optimised, or hacked to get round
some late-breaking design problem.

"The only thing that is worse than pseudo-code [in academic texts] is real
code". I don't actually agree with this, but it has a point. Real code can
be hard to read, unless it is deliberately written for the purposes of
instruction.
 
R

Richard Heathfield

Malcolm McLean said:

"The only thing that is worse than pseudo-code [in academic texts] is
real code".
Bunk.

I don't actually agree with this,

Neither do I.
but it has a point.

No, it doesn't.
Real code can be hard to read,

Then rewrite it so that it is easy to read.
unless it is deliberately written for the purposes of instruction.

All code should be deliberately written for the purposes of instruction.
If your code isn't readable, it isn't finished yet.
 
M

Malcolm McLean

Richard Heathfield said:
Malcolm McLean said:

"The only thing that is worse than pseudo-code [in academic texts] is
real code".
Bunk.

I don't actually agree with this,

Neither do I.
but it has a point.

No, it doesn't.
Real code can be hard to read,

Then rewrite it so that it is easy to read.
unless it is deliberately written for the purposes of instruction.

All code should be deliberately written for the purposes of instruction.
If your code isn't readable, it isn't finished yet.
I'd like to think I follow this rule.
I have policy of releasing everything that I write that might be of use to
anyone else. I can do this because I am funded with public research money.
Obviously matters are different if you are working in the private sector. I
try to always document how the code works, and comment the source, and also
release high quality functions with hacks removed.

The problem is that you never know how people are using your stuff, unless
they actually get back to you, which is rare.
 
B

Ben Pfaff

Richard Heathfield said:
All code should be deliberately written for the purposes of instruction.
If your code isn't readable, it isn't finished yet.

I just found a new signature.
 
P

pete

Richard said:
Malcolm McLean said:

"The only thing that is worse than pseudo-code
[in academic texts] is real code".

Is K&R, an academic text?
Bunk.


Neither do I.


No, it doesn't.

A text description accompanied by C code is best,
but given a choice, if I want to learn an algorithm,
I prefer to see it coded in C,
rather than described in English.

I consider being able to read code, to be a genuine skill.
Then rewrite it so that it is easy to read.

Unless there are reasons for not rewriting it,
I rewrite code that I study, in order to learn it.

"Rewrite the code as part of reading it for the first time.
Nothing else will get you so far so fast." -- Jim Hill, 3 Apr 1993

http://groups.google.com/group/comp.lang.c/msg/aca808679c718d37
 
D

Default User

Malcolm said:
It really isn't.
You should read other people's code of course, but there are all
sorts of reasons why reading working "real" programs won't tell you
how to do a good job yourself.

I agree with this. I believe that reading other's code teaches you how
to read code. This is an important, allied, skill to programming. It
doesn't teach one to programming. You learn that, not surprisingly, by
programming.

I personally think it's a huge mistake for newbies to do what people
often recommend, go and read code off in sourceforge or whatever. I
think they should (after working though a good textbook and doing many
exercises) find a small project that interests them and code it up.




Brian
 
M

Malcolm McLean

pete said:
Richard said:
Malcolm McLean said:

"The only thing that is worse than pseudo-code
[in academic texts] is real code".

Is K&R, an academic text?
No. It's a primer for a computer language. Academic texts describe new
algorithms or mathematical results.
A text description accompanied by C code is best,
but given a choice, if I want to learn an algorithm,
I prefer to see it coded in C,
rather than described in English.
I agree with that. However journal editors normally don't. They want to see
funny E notation rather than loops.
What's annoying is that, without fail, there is always one term in the
expression which isn't properly defined in the text, or is hard to obtain,
like "the second derivative of ..." where ... is some stupidly complex thing
with imaginary numbers and the like all over the place, that is quite beyond
my calculus skills.
 
O

Old Wolf

Since the best way to learn how to program well is to read other
people's programs, which open source projects written in C stand out
as examples of well-written code?

Last time I looked, this project had exceptionally
well laid out source code, compared to other
open-source projects:
ftp://ftp.thangorodrim.net/pub/angband/Source/angband-3.0.6.tar.gz
 
B

Ben Pfaff

David Delony said:
Since the best way to learn how to program well is to read other
people's programs, which open source projects written in C stand out
as examples of well-written code?

If I may be permitted to toot my own horn, I would like to point
to Pintos, an educational operating system, as an example of
well-written, easy to understand code, at
http://www.stanford.edu/class/cs140/pintos/pintos.tar.gz
or
http://www.stanford.edu/class/cs140/pintos/pintos/
It is not strictly conforming C by any stretch of the
imagination.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top