Preface

This simple book is meant to get you started in programming. The title says it’s the hard way to learn to write code, but it’s actually not. It’s only the “hard” way because it uses a technique called instruction. Instruction is where I tell you to do a sequence of controlled exercises designed to build a skill through repetition. This technique works very well with beginners who know nothing and need to acquire basic skills before they can understand more complex topics. It’s used in everything from martial arts to music to even basic math and reading skills.

This book instructs you in Python by slowly building and establishing skills through techniques such as practice and memorization, then applying them to increasingly difficult problems. By the end of the book you will have the tools needed to begin learning more complex programming topics. I like to tell people that my book gives you your “programming black belt.” What this means is that you know the basics well enough to now start learning programming.

If you work hard, take your time, and build these skills, you will learn to code.

Improvements in the Python 3 Edition

Learn Python 3 the Hard Way now uses Python 3.6. I’ve standardized on this version of Python because it has a new, improved string formatting system that is easier to use than the previous 4 (or 3, I forget, there were many) versions. There are a few problems with Python 3.6 for beginners, but I help you navigate these issues in the book. A particularly hairy problem is that Python 3.6 has very poor error messages in some key areas that I help you understand.

I have also improved the videos based on my experiences over the last five years teaching people Python. You can watch these videos online at informit.com/title/9780134692883. In the past the videos simply let you watch me do the exercise. The Python 3 edition videos also show you how to break—and then fix—every exercise. This skill is called “debugging.” It teaches you how to fix problems you run into but also how Python runs the programs you’re creating. The goal of this new methodology is to build a mental model of how Python runs your code so you can more easily figure out why it’s broken. You’ll also learn many useful tricks for debugging broken software.

Last, the Python 3 edition fully supports Microsoft Windows 10 from beginning to end. The previous edition focused mostly on the Unix-style systems such as macOS and Linux, with Windows being more of an afterthought. At the time I started writing the Python 3 edition Microsoft had started to take open source tools and developers seriously, and it was difficult to ignore them as a serious Python development platform. The videos feature Microsoft Windows using Python in various scenarios and also show macOS and Linux for full compatibility. I tell you about any gotchas on each platform, cover installation instructions, and provide any other tips I can give you.

The Hard Way Is Easier

With the help of this book, you will do the incredibly simple things that all programmers do to learn a programming language:

1. Go through each exercise.

2. Type in each file exactly.

3. Make it run.

That’s it. This will be very difficult at first, but stick with it. If you go through this book and do each exercise for one or two hours a night, you will have a good foundation for moving on to another book about Python to continue your studies. This book won’t turn you into a programmer overnight, but it will get you started on the path to learning how to code.

This book’s job is to teach you the three most essential skills that a beginning programmer needs to know: reading and writing, attention to detail, and spotting differences.

Reading and Writing

If you have a problem typing, you will have a problem learning to code, especially if you have a problem typing the fairly odd characters in source code. Without this simple skill you will be unable to learn even the most basic things about how software works.

Typing the code samples and getting them to run will help you learn the names of the symbols, get familiar with typing them, and get you reading the language.

Attention to Detail

The one skill that separates good programmers from bad programmers is attention to detail. In fact, it’s what separates the good from the bad in any profession. You must pay attention to the tiniest details of your work or you will miss important elements of what you create. In programming, this is how you end up with bugs and difficult-to-use systems.

By going through this book, and copying each example exactly, you will be training your brain to focus on the details of what you are doing, as you are doing it.

Spotting Differences

A very important skill (that most programmers develop over time) is the ability to visually notice differences between things. An experienced programmer can take two pieces of code that are slightly different and immediately start pointing out the differences. Programmers have invented tools to make this even easier, but we won’t be using any of these. You first have to train your brain the hard way, then use the tools.

While you do these exercises, typing each one in, you will make mistakes. It’s inevitable; even seasoned programmers would make a few. Your job is to compare what you have written to what’s required and fix all the differences. By doing so, you will train yourself to notice mistakes, bugs, and other problems.

Ask, Don’t Stare

If you write code, you will write bugs. A “bug” means a defect, error, or problem with the code you’ve written. The legends say that this comes from an actual moth that flew into one of the first computers causing it to malfunction. Fixing it required “de-bugging” the computer. In the world of software, there are a lot of bugs. So many.

Like that first moth, your bugs will be hidden somewhere in the code, and you have to go find them. You can’t just sit at your computer screen staring at the words you’ve written hoping that the answer jumps out at you. There is no more additional information you can get doing that, and you need additional information. You need to get up and go find the moth.

To do that you have to interrogate your code and ask it what is going on or look at the problem from a different view. In this book I frequently tell you to “stop staring and ask.” I show you how to make your code tell you everything it can about what’s going on and how to turn this into possible solutions. I also show you how to see your code in different ways, so you can get more information and insight.

Do Not Copy-Paste

You must type each of these exercises in, manually. If you copy-paste, you might as well not even do them. The point of these exercises is to train your hands, your brain, and your mind in how to read, write, and see code. If you copy-paste, you are cheating yourself out of the effectiveness of the lessons.

Using the Included Videos

Learn Python 3 the Hard Way has an extensive set of videos demonstrating how the code works and, most importantly, how to break it. The videos are the perfect place to demonstrate many common errors by breaking the Python code on purpose and showing you how to fix it. I also walk through the code using debugging and interrogation tricks and techniques. The videos are where I show you how to “stop staring and ask” the code what’s wrong. You can watch these videos online at informit.com/title/9780134692883.

A Note on Practice and Persistence

While you are studying programming, I’m studying how to play guitar. I practice it every day for at least two hours a day. I play scales, chords, and arpeggios for an hour and then learn music theory, ear training, songs, and anything else I can. Some days I study guitar and music for eight hours because I feel like it and it’s fun. To me repetitive practice is natural and just how to learn something. I know that to get good at anything I have to practice every day, even if I suck that day (which is often) or it’s difficult. Keep trying, and eventually it’ll be easier and fun.

Between the time that I wrote Learn Python the Hard Way and Learn Ruby the Hard Way I discovered drawing and painting. I fell in love with making visual art at the age of 39 and have been spending every day studying it in much the same way that I studied guitar, music, and programming. I collected books of instructional material, did what the books said, painted every day, and focused on enjoying the process of learning. I am by no means an “artist,” or even that good, but I can now say that I can draw and paint. The same method I’m teaching you in this book applied to my adventures in art. If you break the problem down into small exercises and lessons, and do them every day, you can learn to do almost anything. If you focus on slowly improving and enjoying the learning process, then you will benefit no matter how good you are at it.

As you study this book, and continue with programming, remember that anything worth doing is difficult at first. Maybe you are the kind of person who is afraid of failure, so you give up at the first sign of difficulty. Maybe you never learned self-discipline, so you can’t do anything that’s “boring.” Maybe you were told that you are “gifted,” so you never attempt anything that might make you seem stupid or not a prodigy. Maybe you are competitive and unfairly compare yourself to someone like me who’s been programming for more than 20 years.

Whatever your reason for wanting to quit, keep at it. Force yourself. If you run into a Study Drill you can’t do, or a lesson you just do not understand, then skip it and come back to it later. Just keep going because with programming there’s this very odd thing that happens. At first, you will not understand anything. It’ll be weird, just like with learning any human language. You will struggle with words and not know what symbols are what, and it’ll all be very confusing. Then, one day, BANG—your brain will snap and you will suddenly “get it.” If you keep doing the exercises and keep trying to understand them, you will get it. You might not be a master coder, but you will at least understand how programming works.

If you give up, you won’t ever reach this point. You will hit the first confusing thing (which is everything at first) and then stop. If you keep trying, keep typing it in, keep trying to understand it and reading about it, you will eventually get it. If you go through this whole book, and you still do not understand how to code, at least you gave it a shot. You can say you tried your best and a little more, and it didn’t work out, but at least you tried. You can be proud of that.

Acknowledgments

I would like to thank Angela for helping me with the first two versions of this book. Without her I probably wouldn’t have bothered to finish it at all. She did the copyediting of the first draft and supported me immensely while I wrote it.

I’d also like to thank Greg Newman for doing the original cover art, Brian Shumate for early website designs, and all of the people who read this book and took the time to send me feedback and corrections.

Thank you.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.196.59