2 ms·
I've been working on writing a programming book for quite some time now, and I can tell you that coming up with good examples is really hard. For me, a good ex
by perlgeek 15y ago
I've been working on writing a programming book for quite some time now, and I can tell you that coming up with good examples is really hard.
For me, a good example meets as many as possible of the following demands (in no particular order).
An example should
* demonstrate the feature or concept under discussion
* be short - shouldn't be more than half a page to a page
* solve a problem that the reader can easily understand
* solve an interesting problem
* not use unrelated features of the language or library that haven't been introduced yet
* should avoid complexity unrelated to the feature or concept under discussion
* should be as close as possible to what one would use in "serious" (ie non-teaching) programming
I found that i spent about as much time searching for good examples as actually writing text or code for the book. I'm pretty happy with some of the examples (for example the chapter on grammars parses JSON, which is rather real-world, but not too complicated), some of them still fail most of the demands given above.
(If you're curious, grab the latest PDF from https://github.com/perl6/book/downloads https://github.com/perl6/book/downloads -- it's still very much a work in progress).