Praise for Head First Learn to Code “This is one of the most surprising, entertaining and brilliantly-planned software books I’ve ever read. It’s more interesting and better thought-out than all other beginning programming books I know put together. I run into people all the time who need to learn programming and want to know what course to take; I plan to tell them to forget about courses and get this book instead.” — David Gelernter, Professor of Computer Science, Yale University “Head First Learn to Code has humor, emotions, and step by step instructions. This book turns on your brain, makes you laugh and teaches you to be a code master—it’s a keeper.” — Smore Magazine, a science magazine to know more and be more “The book is a great read, even for an experienced programmer, with new perspectives on how to teach difficult concepts we take for granted. Whether your just starting out or trying to figure out ways to bring more people to code, this book will serve you well. Eric has made learning to code accessible and approachable without dumbing anything down and setting the expectations of effort and difficulty that actually exist.” — Avi Flombaum, Dean and Chief Product Officer of the Flatiron School “As a high school computer science teacher, Head First Learn to Code is my new primary resource for introducing topics to students. It has an immensely personal touch and its conversational nature, humor, and general style make it feel as if you are learning from another human rather than merely reading a piece of text.” — Brandon Shufflebarger, Regents School of Austin “This is the book I wish would have been around when I first started learning to code. Unlike other beginner’s programming books, Freeman strikes a perfect balance of humor, concise tutorials, and helpful background information—without sounding condescending or overly technical. Head First Learn to Code will certainly be a valuable resource for beginning coders at our school fablab.” — Patrick Benfield, Innovation Director, The Magellan International School “It takes talent and creativity to write in such an accessible manner. I am looking forward to using the book next school year in an introductory course. I became enthralled with the relevant and accessible examples that were substantive rather than the typical irrelevant and superficial examples presented to the reader of a typical text on the subject.” — Josh Sharfman, Teacher, Shalhevet Advanced Studies, Computer Science “In keeping with a book about a language named for Monty Python, there’s a lot of meta-humor here about the software industry, about programmer culture, and about tutorial books themselves. It’s nice to be reminded that coding takes place in the (sometimes illogical) world of humans.” — Ethan Hein, Adjunct Professor of Music Technology at NYU and Montclair State University.
ttaabbllee ooff ccoonntteennttss Table of Contents (summary) Intro xxv 1 Getting started: Thinking computationally 1 2 Know your value: Simple values, variables, and types 33 3 Decisive code: Booleans, decisions, and loops 73 4 Providing some structure: Lists and iteration 125 5 Getting functional: Functions and abstraction 179 4b Putting some order in your data: Sorting and nested iteration 225 6 Putting it all together: Text, strings, and heuristics 245 7 Getting modular: Modules, methods, classes, and objects 291 8 Beyond iteration and indices: Recursion and dictionaries 341 9 Persistence: Saving and retrieving files 393 10 You really should get out more: Using web APIs 435 11 Getting interactive: Widgets, events, and emergent behavior 467 12 A trip to Objectville: Object-oriented programming 523 Appendix: The Top Ten Topics (we didn’t cover): Leftovers 575 Table of Contents (the real thing) Intro Your brain on coding. Here you are trying to learn something, while here your brain is doing you a favor by making sure the learning doesn’t stick. Your brain’s thinking, “Better leave room for more important things, like which wild animals to avoid and whether naked snowboarding is a bad idea.” So how do you trick your brain into thinking that your life depends on knowing how to code? Who is this book for? xxvi We know what you’re thinking xxvii We think of a “Head First” reader as a learner xxviii Metacognition: thinking about thinking xxix Here’s what WE did xxx Here’s what YOU can do to bend your brain into submission xxxi Read Me xxxii Acknowledgments xxxvii The Review Team xxxviii ix.
how to use this book Intro I can’t believe they put that in a book on learning to code! “ISno t, hwish ys eDctIDion t, hweey apnustw etrh atth ein b au rbnoinogk qoune slteaiornn:i n g t o c o de?” xxv.
how to use this book Who is this book for? This is NOT a reference book. If you can answer “yes” to all of these: Head First Learn to Code is a Do you want to learn, understand, and remember how 1 book designed to program? for learning to Do you prefer stimulating dinner party conversation 2 code. It’s not an to dry, dull, academic lectures? encyclopedia of programming facts this book is for you.
the intro Metacognition: thinking about thinking If you really want to learn, and you want to learn more quickly and more deeply, I wonder how I pay attention to how you pay attention. Think about how you think. Learn how you can trick my brain learn.
how to use this book Here’s what WE did: We used pictures, because your brain is tuned for visuals, not text. As far as your brain’s concerned, a picture really is worth 1,024 words. And when text and pictures work together, we embedded the text in the pictures because your brain works more effectively when the text is within the thing the text refers to, as opposed to in a caption or buried in the text somewhere.
the intro Here’s what YOU can do to bend your brain into submission So, we did our part. The rest is up to you. These tips are a starting point; listen to your brain and figure out what works Cut this outfo ra nydo ust aicnkd itw hat doesn’t. Try new things.
how to use this book Read Me This is a learning experience, not a reference book. We deliberately stripped out everything that might get in the way of learning whatever it is we’re working on at that point in the book. And the first time through, you need to begin at the beginning, because the book makes assumptions about what you’ve already seen and learned.