Learning to Program, 1st edition

Published by Addison-Wesley Professional (November 4, 2014) © 2015

  • Steven Foote
$27.99

  • A print text (hardcover or paperback) 
  • Free shipping
  • Also available for purchase as an ebook from all major ebook resellers, including InformIT.com

Learning to Program will help students build a solid foundation in programming that can prepare them to achieve just about any programming goal. Whether they want to become a professional software programmer, learn how to more effectively communicate with programmers, or are just curious about how programming works, this book is a great first step in helping to get there.

  • Teaches ideas and techniques that can be used in practically any modern programming language
  • Demystifies program organization, accessing and storing data, controlling program flow, testing, debugging, reusing code, and much more
  • Illustrated with easy, brief hands-on projects for building simple, useful Chrome extensions

Introduction Why I Wrote This Book 1

    Why You Should Read This Book 3

    Your Project 3

1 “Hello, World!” Writing Your First Program 5

    Choose a Text Editor 5

        Core Features 6

    Making Your Choice 8

        Sublime Text 9

        TextMate 9

        Notepad++ 9

        Gedit 9

        Vim 10

        Eclipse 10

        IntelliJ 11

        Xcode 11

        Visual Studio 11

    Create a Project Directory 12

    Start Small: Create a Test File 12

        How HTML and JavaScript Work Together in a Browser 13

        The Value of Small Changes 15

    Build on Your Success 17

        Reference Your JavaScript in manifest.json 20

        Let It Run! 20

    Great Power, Great Responsibility 21

    Summing Up 21

2 How Software Works 23

    What Is “Software”? 23

    Software Life Cycle 24

    Source Code—Where It All Starts 25

        A Set of Instructions 25

        Programming Languages 26

        From Source Code to 0’s and 1’s 31

        Compiled vs. Interpreted Languages: When Does the Source Code Become Binary? 31

        Runtime Environment 32

        Execution by the Processor 34

    Input and Output 34

        Making Software Useful (and Reusable) with Input 34

        Where Does the Input Come From? 35

        How the Software Gets the Input 36

        Types of Output 36

        GIGO: Garbage In, Garbage Out 37

        State 38

        Add State to Kittenbook 39

    Memory and Variables 41

        Variables 41

        Variable Storage 42

        A Finite Resource 44

        Memory Leaks 44

    Summing Up 45

3 Getting to Know Your Computer 47

    Your Computer Is Stupid 47

    Your Computer Is Magic 48

        Standing on the Shoulders of Giants 48

    Computer Guts 48

        Processor 48

        Short-Term Memory 49

        Long-Term Memory 49

    Using Your Computer 50

        The File System 50

        The Command Line: Take Control 52

    Summing Up 62

4 Build Tools 63

    Automate (Almost) Everything 63

        Install Node 64

        Install Grunt 66

        Software That Helps You Create Software 69

        Avoid Mistakes 70

        Work Faster 70

    Tasks to Automate 70

        Compile 71

        Test 71

        Package 72

        Deploy 72

    Build Your Own Build 72

        Gruntfile.js 73

        Use Grunt Plug-ins 73

        Load Grunt Plug-ins 76

        Register Tasks 76

    Watch This! 78

    Summing Up 80

5 Data (Types), Data (Structures), Data(bases) 83

    Data Types 83

        Why Different Data Types Exist 84

        Primitive Data Types 84

        Composite Data Types 89

        Dynamically and Statically Typed Languages 96

    Data Structures 96

        Set 99

        Stack 99

        Tree 100

        Graph 101

        How to Choose an Effective Data Structure 104

    Databases 104

        Long-Term (Persistent) Storage 104

        Relational Databases 104

        A Brief Introduction to SQL 106

    Summing Up 107

6 Regular Expressions 109

    Ctrl+F on Steroids: Looking for Patterns 109

    Using Regular Expressions in JavaScript 110

    Repetition 111

        ? 111

        + 111

        * 112

        Special Characters and Escaping 112

        {1,10}: Make Your Own Super Powers 113

        Match Anything, Period 113

        Don’t Be Greedy 114

    Understanding Brackets from [A-Za-z] 115

        Lists of Characters 115

        Ranges 115

        Negation 116

    A Pattern for Phone Numbers 116

    I Need My \s 119

        Shortcuts for Brackets 119

        Limitations 121

        Capture the Tag 124

        Advanced Find and Replace 125

        The Beginning and the End (of a Line) 126

    Flags 126

        Global 126

        Ignore Case 126

        Multiline 127

    When Will You Ever Use Regex? 127

        grep 127

        Code Refactoring 127

        Validation 128

        Data Extraction 128

    Summing Up 129

7 if, for, while, and When 131

    Operators 131

        Comparison Operators 131

        Logical Operators 132

        Unary Operators 134

        Binary Operators 134

        Ternary Operators 136

        “Truthy” and “Falsy” 139

        “Syntactic Sugar” 140

        Looping Through an Array 142

        Looping Through Images 142

        Nested Loops 143

        You Need a Break 143

        Infinite Loops 145

        Take Another Break 146

        When You Don’t Know When to Stop 146

    When 147

        Events 147

        Listeners 147

        Cron Jobs 148

        Timeouts 149

        Catch When Things Go Wrong 150

        Writing Robust Code 151

    Summing Up 151

8 Functions and Methods 153

    Function Structure 153

        Definition 154

        Invocation 154

        Arguments 155

        Call Stack 157

    Code Encapsulation 158

        Do One Thing Well 158

        Divide and Conquer 159

        A Place for Everything and Everything in Its Place 162

    Code Reuse 163

        Solve the General Problem 163

        Do More with Less 163

        Don’t Repeat Yourself (DRY) 165

    Scope 166

        Global 167

        Local 168

        How Variable Lookups Happen 168

    Summing Up 171

9 Programming Standards 173

    Coding Conventions 173

        Setting Standards 174

        To Hack or Not to Hack 174

        Pay Now or Pay Later 175

        Writing Maintainable Code 175

    Code Formatting 176

        Keep It Consistent 177

        Whitespace 178

    It Doesn’t Happen on Its Own: Make Rules 178

    Using the Work of Others 180

        Build Faster 180

        Open Source Software 181

        Built by the Community 181

        When to Build It Yourself 182

    Best Practices 182

        Documentation 182

        Planning 183

        Testing 183

    Summing Up 183

10 Documentation 185

    Document Intentions 186

        Self-Documenting Code 187

        Don’t Document the Obvious 189

        The Danger of Outdated Documentation 190

        Find Bugs Using Documentation 191

    Document for Yourself 191

        How Good Is Your Memory? 191

        Document to Learn 192

        Documentation Beyond Comments 192

    Document for Others 196

        Document Your Decisions 196

        Document Your Resources 197

        Document to Teach 197

    Summing Up 198

11 Planning 199

    Think Before You Build 199

    Create a Specification 200

    Design an Architecture 200

        Draw Diagrams 201

        Try to Break Your System 202

    Iterative Planning 203

    Design for Extensibility 203

    What Are Your Priorities? 204

        User Experience 204

        Performance 204

        Security 205

        Scalability 205

        Deadlines 205

    The Balancing Act 206

        Identify and Create Constraints 206

        Know What You Can and Can’t Do 206

    Summing Up 207

12 Testing and Debugging 209

    Manual Testing 209

        Test As You Work 210

        Try Something Crazy 210

        Eat Your Own Dog Food 211

    Automated Testing 211

        Unit Tests 212

        Set Up Tests for Kittenbook 215

        Epic Fail! 218

        Spies Like Us (and We Like Spies) 219

    Integration Tests 221

        Catch Problems Early 222

    Debugging 222

        Errors 223

        Logs 224

        Breakpoints 224

        Inspecting, Watching, and the Console 228

        Stepping Through the Code 229

        Call Stack 231

        Find the Root Cause 231

        Code, Test, Debug, Repeat 232

    Summing Up 232

13 Learning to Fish: How to Acquire a Lifetime of Programming Knowledge 233

    How to Search 234

        Finding the Right Terms 235

        Working Backward 236

        Identifying Quality Resources 236

        Personal Blogs: Hidden Gems 237

    Where, When, and How to Ask Programming Questions 237

        Where 237

        When 240

        How 241

        Learn by Teaching 241

    Summing Up 242

14 Building Your Skills 243

    Make kittenbook Your Own 243

        Restyle Facebook 243

        Add New Functionality 244

        Share Your Version of Kittenbook 245

    Find Your Own Project 246

        Solve Your Own Problem 246

        Be Ambitious 246

        Get Help, Give Help 247

    Open Source Projects 247

        GitHub 247

        Finding a Project 248

        Different Ways to Contribute 248

        Create Your Own 249

    Free Online Education 249

        Project Euler 249

        Udacity 250

        Coursera 250

        codecademy 251

        Khan Academy 251

        Tutorials 251

    Paid Education 252

        Read a Book 252

        Udacity and Coursera 252

        Treehouse 253

    Summing Up 253

15 Advanced Topics 255

    Version Control 255

        Why Use Version Control? 256

        Working with a Team 257

        Subversion 260

        Git 260

    OOP (Object-Oriented Programming) 265

        Classes 266

        Inheritance 266

        Instances 267

    Design Patterns 268

        Pub Sub 268

        Mediator 269

        Singleton 270

    Summing Up 270

Glossary 273

TOC, 9780789753397, 10/13/2014

 

Steven Foote is a web developer at LinkedIn. A self-taught programmer who loves technology, especially the Web, he has a Bachelor’s degree and Master’s degree in Accountancy from Brigham Young University. While working on his Master’s degree, he built all aspects of two AJAX-y web applications, from visual design to server and database maintenance, and everything in between.

Need help? Get in touch

Video
Play
Privacy and cookies
By watching, you agree Pearson can share your viewership data for marketing and analytics for one year, revocable upon changing cookie preferences. Disabling cookies may affect video functionality. More info...

Pearson eTextbook: What’s on the inside just might surprise you

They say you can’t judge a book by its cover. It’s the same with your students. Meet each one right where they are with an engaging, interactive, personalized learning experience that goes beyond the textbook to fit any schedule, any budget, and any lifestyle.