Wallace Wang

Beginning Programming All-in-One For Dummies


Скачать книгу

the time to understand

      Programming is a skill that anyone can acquire. Like any skill, the best way to understand is to take the time to experiment, make mistakes, and learn from your failures. Some programmers prefer to spend their time mastering a single programming language. Others prefer to master the intricacies of writing programs for a specific operating system, such as Windows. Still others spend their time discovering a variety of programming languages and writing programs for different operating systems.

      There is no right or wrong way to figure out programming. The only “right” way is the way that works for you. That’s why self-taught programmers can often write programs that are just as good as (or even better than) programs written by PhD computer scientists.

      Believe it or not, programming a computer is actually fairly straightforward. The hard part is trying to write a program that actually works.

      There’s a big difference between knowing how to program and knowing a specific programming language. This book describes how programming works, which means you’ll understand the principles behind programming no matter what programming language you decide to use.

      When you understand a specific programming language, you’ll figure out how to write a program using that language. Don’t confuse knowing how to program with knowing a programming language!

      When people learn to speak their native language, they often think their particular spoken language is the only way to talk. So, when they learn a foreign language, they try to speak the foreign language just like they speak their native language, but using different words. That’s why literal translations of foreign languages can sound so funny and awkward to a native speaker.

      That’s exactly the same problem with understanding programming. To understand programming, you have to use a specific programming language, but each programming language works a certain way. So, if you know how to write programs in the C programming language, you may mistakenly think that the way the C language works is the way computer programming also works, but that’s not true.

      Like human languages, programming languages differ wildly. Someone who knows how to write programs in the C language thinks differently about programming than someone who knows how to write programs in assembly language.

      To describe how programming works, this book uses a variety of examples from different programming languages. You don’t have to understand how each program example in this book works. Just understand that programming languages can look and solve identical problems in very different ways.

      First, try to understand general programming principles without worrying about the way a particular programming language works. Then try to understand how a particular programming language works. As long as you know how to keep these two topics separate, you can figure out how to program a computer without the distraction of knowing a particular programming language.

      Besides, programming languages rise and fall in popularity all the time, so if you know only one programming language, your skills may become obsolete within a few years.

      At one time, most programmers used assembly language. For programmers who wanted a simpler language, they used BASIC or Pascal. When BASIC and Pascal fell out of favor, programmers gravitated toward C. Because C was so dangerous to use, many people started using C++ and Java. Microsoft created its own version of C++ called C#. Apple initially adopted a language similar to C++ called Objective-C, but then it created its own language called Swift. After running into legal problems using Java, Google adopted Kotlin as the official language for writing Android apps.

      When learning any programming language, the only certainty is that new programming languages will appear all the time, so you should master the popular programming languages and keep learning the newer ones as well.

      Remember: Focus on understanding programming, and then worry about understanding a particular programming language. After you understand how programming works, you can adapt to the next popular programming language of tomorrow, whatever that may be.

      Different Methods for Writing Programs

      IN THIS CHAPTER

      

Spaghetti programming without a plan

      

Planning ahead with structured programming

      

Making user interfaces with event-driven programming

      

Organizing a program with object-oriented programming

      

Using protocol-oriented programming

      

Using design patterns

      The goal of computer science is to find the best ways to write a program. The reality of computer science is that nobody really knows what they’re doing, so they’re making up stuff as they go along and pretending there’s a scientific basis for everything they do. The fact that multimillion-dollar programming projects routinely fall behind schedule and sometimes never work at all pretty much shows that computer programming is still less a science than an art.

      Despite these problems, computer scientists are always searching for ways to make programming easier, faster, and more reliable by constantly developing

       Better tools

       Better programming languages

       Better techniques for writing programs

      Another way to improve programmer efficiency involves creating better programming languages. Assembly language was easier to write and modify than machine language, and high-level languages are easier to write and modify than assembly language.

      Computer scientists are constantly inventing new programming languages or improving existing ones. These improvements or new languages typically offer some feature that existing languages don’t offer or solve certain types of problems that existing languages do poorly. For example, the C++ language improves upon the C language, whereas the Java language improves upon the C++ language.

      Perhaps two of the biggest problems with programming involve writing a program from scratch and modifying an existing program. When you write a program from scratch, you want to write a working program quickly with as few problems as possible.

      That’s why programming languages include so many built-in commands.