Beginning Programming All-in-One For Dummies. Wallace Wang. Читать онлайн. Newlib. NEWLIB.NET

Автор: Wallace Wang
Издательство: John Wiley & Sons Limited
Серия:
Жанр произведения: Программы
Год издания: 0
isbn: 9781119884422
Скачать книгу
alt="Technicalstuff"/> Because C lets you directly control the processor like assembly language does, but still write programs that look somewhat understandable and easy to read and write, many operating systems — such as Linux, macOS, and Microsoft Windows — are written all or partially in C.

      Weighing the pros and cons of programming languages

      The whole purpose of machine language, assembly language, high-level language, and the C language is to give you different ways to give instructions to the processor (computer). Ultimately, it doesn’t matter which type of programming language you use because it’s possible to write the exact same program in machine language, assembly language, a high-level language (like BASIC or Fortran), and C.

      The only difference is that writing a program in machine language takes a really long time and is very difficult to write, fix, and understand. A similar program written in assembly language is smaller and simpler than an equivalent machine language program.

      So, given these advantages of C or high-level languages, why would anyone ever use machine language or assembly language? The answer is simple: speed and efficiency.

      If you want to write the fastest program possible that uses the least amount of memory, use machine language because machine language is the native language of all computers. Unfortunately, machine language is so hard to understand, write, and modify that writing anything but small programs in machine language is nearly impossible.

      Instead of using machine language, most programmers use assembly language when they need speed and efficiency. Assembly language creates small and fast programs, but they’ll never be as small or fast as machine language programs. That’s because processors understand only machine language, so when you write an assembly language program, you have to translate that assembly language program into machine language.

      Translating assembly language into machine language by hand would be slow and error-prone, so computer scientists have created special programs that can do this automatically. These programs are assemblers.

      An assembler takes an assembly language program and converts it into machine language, but this conversion process isn’t perfect. That’s why assembly language tends to create bigger and slower programs than equivalent handcrafted machine language programs. However, assembly language programs are much easier to write and modify later than machine language programs are, so assembly language is used much more often than machine language.

      High-level languages are much easier to write and understand than machine language or assembly language. The problem is that processors don’t understand high-level languages either, so you have to translate a high-level language program into equivalent machine language commands.

      Doing this by hand is nearly impossible, so computer scientists have created special programs — compilers — to do this for them. A compiler takes a program written in a high-level language and translates it into equivalent commands written in machine language.

      As a general rule, if you want to make programming easy where speed and efficiency aren’t that crucial, use a high-level programming language. If you want to make a small and fast program and don’t care how inconvenient it may be to write it, use machine language or assembly language.

      What if you want to write a big and fast program (like an operating system or word processor) and also make it convenient for you to write? You’d use the C programming language.

      

Although C is a fast and powerful language, it’s not the safest. C lets you access all parts of a computer, which means if you’re not careful, your programs can corrupt the computer’s memory (known as memory leaks) and cause all types of unintended havoc. For that reason, computer scientists have used C as a reference to create “safer” versions of the language. Many of today’s popular programming languages (such as C#, Java, Objective-C, Python, and Swift) have been directly or indirectly inspired by C. Because C uses curly brackets to define the beginning and end of code blocks, C-based languages are often called curly-bracket languages.

      

Ultimately, no one cares what language you use as long as your program works. A program that works is far better than a small, fast, and efficient program that doesn’t work. Think of a programming language as a tool. A good programmer can use any tool well, but a bad programmer can screw up using the best tool in the world. The programmer’s skill always determines the quality of any program; the type of programming language used is always secondary. So the goal isn’t to become a “C programmer” or a “Fortran programmer.” The goal is to become a good programmer, regardless of the language you ultimately use.

       Desire

       A computer

       An editor

       An assembler or compiler

       A lot of time on your hands

      

Find out more about programming tools, like an editor and a compiler, in Book 1, Chapter 4.

      Desire beats technical training every time

      Desire is probably the biggest factor in studying how to program a computer. Many people think that you need a college degree or a mathematical background to know computer programming. Although a college degree and a mathematical background can definitely help, they aren’t necessary. Saying you need to know math before figuring out computer programming is like saying you need a college degree in biology before you can reproduce.

      Some of the most influential and popular programs in the world were created by people who had no formal training in computer programming or computer science. (Conversely, some of the most intelligent PhD candidates in computer science have done nothing to make this world a better place using their programming skills.)

      So, if you have an idea for a program, you can create it. After you have the desire to understand computer programming, you have (almost) everything you need to program a computer.

      Picking a computer and an operating system

      If you want to know how to program a computer, you need a computer to practice on. You can actually discover programming on any computer, from a top-of-the-line machine to an obsolete relic (that was once a top-of-the-line machine) to a simple handheld computer. As long as you have a computer, you can figure out how to program it.