Praise for The Rules of Programming
The Rules of Programming combines great guidance for beginners with subtle lessons that may teach even the experts. Zimmerman keeps it fun, tooproving that its possible to be both entertaining and instructive.
Mark Cerny, Lead System Architect, PlayStation 4 and 5
The Rules of Programming provides great insights for both new and experienced coders. Zimmermans style makes it an entertaining read, and the 21 rules are an important contribution to better software at a time when technology is pervasive in every part of business and society.
Paul Daugherty, Group Chief Executive of Technology and CTO, Accenture
The Rules of Programming is full of pragmatic rules of thumb any software engineer can use to level up their skills. I was fortunate to learn these lessons directly from Chris early in my career, and have successfully applied them across a wide variety of software disciplines. With this book, you have the opportunity to do the same.
Chris Bentzel, Director of Software, Boston Dynamics
The Rules of Programming
by Chris Zimmerman
Copyright 2023 Chris Zimmerman. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com.
- Acquisitions Editor: Mary Treseler
- Development Editor: Sarah Grey
- Production Editor: Gregory Hyman
- Copyeditor: Charles Roumeliotis
- Proofreader: Kim Cofer
- Indexer: Potomac Indexing, LLC
- Interior Designer: Monica Kamsvaag
- Cover Designer: Susan Thompson
- December 2022: First Edition
Revision History for the First Edition
- 2022-12-09: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781098133115 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. The Rules of Programming, the cover image, and related trade dress are trademarks of OReilly Media, Inc.
The views expressed in this work are those of the author and do not represent the publishers views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-098-13311-5
[LSI]
Preface
Welcome to The Rules of Programming, a set of easy-to-remember and easy-to-apply Rules that will help you write better code. Programming is hard, but following the Rules makes it a little bit easier.
Here are some tips on reading the book:
All of the Rules stand on their own. If you see an interesting-looking Rule in the table of contents and want to jump straight into the middle of the book, feel free. That reading pattern is fully supported.
That said, Id suggest starting off with . Its a good setup for the rest of the Rules.
The examples in the book are all written in C++. If youre a Python or JavaScript programmer, youll be happier if you read .
If youre a C++ programmer, note that Ive simplified a few things in the code examples to make them easier to read for non-C++ programmers. For example, the examples use signed integers in a few places where unsigned integers would be more typical for a C++ program, and I disabled warnings about implicit conversion between signed and unsigned values. I also compiled the examples with an implicit using std to avoid a boatload of distracting std:: references.
And finally, Im capitalizing Rule when I refer to an actual Rule in the book. If you see rule, its just a regular old rule, not an officially sanctioned one. The distinction between the two senses of the word was confusing without the capitalization; I hope that excuses me.
I hope you enjoy what follows! I think youll discover a few useful thoughts that help you sharpen your programming skills.
Girls Who Code
All royalties from this book go to Girls Who Code, an organization working hard to help young women discover just how rewarding programming can be. When I graduated from college, over a third of computer science graduates were women; these days, its more like a fifth. I think wed all be better off with a more representative gender balance. You probably do, too. And supporting Girls Who Code through donations or volunteering is a step toward making that hope a reality.
Conventions Used in This Book
The following typographical conventions are used in this book:
ItalicIndicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.
Using Code Examples
Supplemental material (code examples, exercises, etc.) is available for download at https://oreil.ly/rules-of-programming-code.
If you have a technical question or a problem using the code examples, please send email to .
This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless youre reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing examples from OReilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your products documentation does require permission.
We appreciate, but generally do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: The Rules of Programming by Chris Zimmerman (OReilly). Copyright 2023 Chris Zimmerman, 978-1-098-13311-5.
If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .
OReilly Online Learning
Note
For more than 40 years, OReilly Media has provided technology and business training, knowledge, and insight to help companies succeed.
Our unique network of experts and innovators share their knowledge and expertise through books, articles, and our online learning platform. OReillys online learning platform gives you on-demand access to live training courses, in-depth learning paths, interactive coding environments, and a vast collection of text and video from OReilly and 200+ other publishers. For more information, visit