Copyrighted Material
Total Page:16
File Type:pdf, Size:1020Kb
02_584065 ftoc.qxd 3/7/05 7:23 PM Page vii Contents Introduction xvii Chapter 1: What Is Programming? 1 The History of Programming 1 What Is Programming? 4 Why So Many Programming Languages? 4 Different Code, Same Results 6 BASIC 7 Atari BASIC 7 C 7 C++ 7 COBOL 8 FORTRAN 8 Java 8 JavaScript 9 Mathematica 9 Pascal 9 Perl 9 Python 9 QBASIC 9 Smalltalk 9 Visual Basic 9 VRML 10 Programs Needed to Create Programs 11 Development Environment 11 Compilers 11 Summary COPYRIGHTED MATERIAL 12 Chapter 2: Why Learn to Program? 13 Why Program? 13 The “Career” Programmer 14 Problem Solving 16 How Big Is the Project? 17 Is the Project Time Critical? 17 Work or Hobby? 17 02_584065 ftoc.qxd 3/7/05 7:23 PM Page viii Contents Because You Want to Contribute 18 Just for Fun 18 Fame 18 What to Learn? 19 Programming Avenues 19 Traditional Programming 19 Web Programming 21 Programming Myths and Facts 23 Myth 1 — Programming Tools Cost a Lot of Money 23 Myth 2 — You Need a Degree in Computer Science to be a Programmer 24 Myth 3 — Learning to Program Takes Years 24 Myth 4 — Programming Is Just for Young People 24 Myth 5 — I’ll Need a Top-of-the-Range Super-Duper Computer to Program On 24 Myth 6 — Programming Is Addictive! 24 Myth 7 — Programming Languages Change All the Time 25 Myth 8 — Once You’ve Learned One Programming Language, Learning Others Is Easier 25 Summary 25 Chapter 3: How Computers “Read” Code 27 Reading Code 27 Top Down 28 Breaking Up Code 31 The Statement 35 Functions/Procedures 36 The Sentences and Paragraphs of Programming 37 Lines of Code 37 Paragraphs of Code 38 Data Storage 39 Data 40 Summary 42 Chapter 4: From Concepts to Code — The Language of Code 43 Binary 44 Interpreting Binary 44 Large Numbers 46 Bit Grouping 47 Bit 47 Nybble 47 Byte 48 Halfword 48 Word 49 Doubleword 50 viii 02_584065 ftoc.qxd 3/7/05 7:23 PM Page ix Contents Binary Math 50 Using Windows Calculator 51 Why Binary? 54 Hexadecimal 54 Interpreting Hexadecimal 55 Hexadecimal and Windows Calculator 57 Representing Characters 57 Operators 65 Arithmetic Operators 65 Assignment Operators 66 Comparison Operators 66 Logical Operators 67 String Operators 68 Summary 69 Chapter 5: The Tools for Programming 71 Make Your Workspace Your Own 71 The Keyboard 71 Workspace 73 Desk 73 Monitor 73 Fonts 73 Choose Your Language 75 Learning to Program 76 School/College 77 Tips 77 Work-Based Training 77 Tips 78 Hobby Programmer 78 Tip 79 The Languages 79 How I Will Teach You to Program 79 Why Not Buy a Book Covering a Specific Language? 80 The Tools 80 General Tools and Utilities 80 Text Editor 80 Utilities 83 Programming Tools 87 Java 89 C++ 91 Scripting Languages 94 Summary 95 ix 02_584065 ftoc.qxd 3/7/05 7:23 PM Page x Contents Chapter 6: Simple Coding 97 Commenting Code 97 VBScript Comments 98 Things to Watch For 100 Quick Exercise 100 JavaScript Comments 101 Things to Watch For 102 Quick Exercise 102 C++ Comments 103 Things to Watch For 103 Quick Exercise 104 Variables 104 Variables in Action 107 Variable Run Through 107 Naming Variables 118 Naming of Variables 121 Quick Exercise 124 Strings 124 What Are Strings? 124 String Manipulation 126 Processing Inputs 130 Variable Manipulation — Simple Math 132 Summary 136 Chapter 7: The Structure of Coding 137 The Purpose of Structure 137 Benefits 138 Examining Structure 138 Quick Introduction to C++ 138 Examine Source Code 138 Compiling C++ 141 Functions 149 More Functions 152 Quick Exercise 156 Conditionals 157 Programming Decisions 157 Conditions 158 More on Conditionals 163 Quick Exercise 171 Loops 173 For Loops 173 Infinite Loops 175 While Loops 175 x 02_584065 ftoc.qxd 3/7/05 7:23 PM Page xi Contents Do While loop 176 Quick Exercise 177 Arrays 179 Two-Dimensional Array 180 Multidimensional Array 181 Quick Exercise 182 Summary 183 Chapter 8: Problem Solving 185 The Basics of Problem Solving 186 Be Clear about the Requirements 186 Research 191 Breaking the Problem up into Smaller Problems 194 What Are the Issues That the Application Needs to Deal With? 195 Moving on to the Coding Phase 196 Improving the Code 204 Summary 212 Chapter 9: Debugging 213 To Err Is Human 213 Errors, Errors, Errors! 214 Different Kinds of Error 214 Compiler Error 214 Runtime Errors 228 Logic Errors 232 Spotting Errors 236 Read Each Line After You Press Enter 236 Check the Preceding Statements 237 Keep the Layout Clear 237 Comments, Comments, Comments! 237 Remove Ambiguity in Code 238 Semicolons 238 Test the Code 239 Keep Track of Variables 239 Summary 245 Chapter 10: Interface 247 What Is an Interface? 247 The Importance of an Interface 250 What Is an Interface? 250 Does All Software Have an Interface? 251 xi 02_584065 ftoc.qxd 3/7/05 7:23 PM Page xii Contents Examining the Interface 251 Text-Based Interface 251 Program Overview 254 Proper Prompting for Input 256 Annotating Output 259 Confirming Exit 260 Adding Simple Help 261 Confirmations 267 Moving Away from the Text-Based Interface 268 Buttons 268 Menus 270 Check Box 271 Radio Buttons 272 Single-Line Text Box 273 Multiline Text Box 274 Drop-Down Menu 275 Putting It All Together 275 Simple Applications 276 More Complicated Applications 280 Summary 283 Chapter 11: Putting It All Together 285 Planning a Programming Project 285 Without Planning 285 More Code, Less Features 285 More Bugs 286 Project Takes Longer 286 Missing Features 286 Planning 286 The Idea 286 Documenting the Idea 287 Maturing Time 289 The Requirements 290 Requirements 290 Programming Stage 293 Programming the Basics 293 Testing 293 Commenting Code 294 Testing 296 The Route to Better Testing 297 But What About . 298 Questions for Those Previewing Software 298 xii 02_584065 ftoc.qxd 3/7/05 7:23 PM Page xiii Contents Additional Features 299 Tweak the Code 300 Final Testing 300 Summary 301 Chapter 12: Interacting with Files 303 The Principles of Saving Data 303 The File Life Cycle 304 Working with Files 306 The Tools 306 Getting Started 306 Creating a File with VBScript 307 Basics 307 Creating a Folder 310 Creating Multiple Files 311 Making Use of Conditionals 312 Making Use of Variables 313 Adding Flexibility — Prompt for File and Folder Names 314 Check for Duplicate Files 317 Editing an Existing File 317 In Action 319 Appending a File 319 Open File for Reading 320 ReadAll, ReadLine, and Read Methods 321 ReadAll 321 ReadLine 322 Read 323 Deleting Files and Folders 325 Delete Files 325 Delete Folders 325 Summary 326 Chapter 13: The Windows Registry 327 The Windows Registry 327 What Is the Windows Registry? 327 Definition 328 The Layout of the Windows Registry 329 Regedit and Regedit32 329 Backing Up the Registry 330 Windows XP 330 Restoring the Registry 339 xiii 02_584065 ftoc.qxd 3/7/05 7:23 PM Page xiv Contents Working with the Registry 341 Finding a Subtree, Key, Subkey, or Value 341 Adding a New subkey 343 Adding a New Value 344 Changing an Existing Value 346 Renaming an Existing Subkey or a Value 347 Deleting an Existing Subkey or a Value 348 Manipulating the Windows Registry Using Programming 349 VBScript Registry Editing 349 JScript Registry Editing 354 Possible Uses for the Windows Registry 355 In Closing 356 Summary 357 Chapter 14: Organizing, Planning, and Version Control 359 Organize, Organize, Organize! 359 Organize Yourself 359 Stages of Planning 360 Plan Your Time 360 Organize Your Workspace 360 The Main Event — Organize Your PC 362 Create a Workspace 362 Folders, Folders, Folders 364 Group by Language 364 Group by Project 365 Folder Contents Note 366 Filename Control 368 More Version Control Tips 370 Add Version Information to the Tombstone Comment Block 370 Using Windows Search 371 Add Summary Information to the File 373 Version Control — Looking Beyond Release 376 Software Version Control 377 Summary 377 Chapter 15: Compiling Code and Alternatives to Compiling 379 Compiling Code 379 Are All Compilers the Same? 381 Error Handling 387 What about Different Languages? 391 xiv 02_584065 ftoc.qxd 3/7/05 7:23 PM Page xv Contents Benefits of Compiling 394 Protection of Intellectual Property 395 Speed 395 Increased Functionality 396 Security 396 Debugging 397 Alternatives to Compiled Code 397 Make Code Hard to Follow 397 Obscure Variable Names 397 Whitespace 398 Script Encoding 398 Summary 404 Chapter 16: Distributing Your Project 405 Types of Distribution 405 Physical Distribution 405 Floppy Disk 406 CDs 409 DVD 411 Burning Discs 412 CD/DVD Burner 412 Burning Software 414 CD/DVDs 419 Labeling 420 Packaging 420 Virtual Distribution 421 Pros of Virtual Distribution 421 Cons of Virtual Distribution 422 Considerations for Virtual Distribution 422 Full-Time Job versus Hobby 423 Supported versus Unsupported 424 Summary 425 Appendix A: Glossary 427 Appendix B: Web Resources 433 Programming Tools 433 Java Tools 435 Java Sites 436 xv 02_584065 ftoc.qxd 3/7/05 7:23 PM Page xvi Contents C++ Tools 437 C++ Sites 438 BASIC Tools 439 BASIC Sites 440 Web Scripting Languages 441 CD Burning 441 Compression Tools 442 Miscellaneous Tools 444 Miscellaneous Sites 446 Index 447 xvi.