HACKER Q&A
📣 billconan

What's the ideal way of showing code in a technical book?


Hello HN,

I'm currently working on a technical book focused on graphics programming. One challenge I'm encountering is that the graphics programming APIs tend to be very verbose, resulting in sample code that is quite lengthy. If I include the full source code for each example, a significant portion of the book will be occupied by code, which may not be the most useful approach. Instead, I want to prioritize providing detailed explanations.

However, if I only include a few lines of code relevant to each explanation, I'm concerned that readers may struggle to see the big picture and connect the dots between different concepts.

Have you come across any books that handle this balance effectively? I'm eager to learn from their approach. Additionally, any other suggestions regarding the format of a traditional technical book are welcome.

Thank you.


  👤 sinuhe69 Accepted Answer ✓
I propose a dual mode:

- full code and samples in a easy access repository.

- Even better: the code are runnable using a online editor with compiler

- only three most meaningful parts are printed in the book.

For the printed code, you can introduce the boilerplates once then mark them in the successive sections.


👤 stop50
i saw some repos on github that provide the "end result" in a repo. Can't rembember which one.