ТОП просматриваемых книг сайта:
Beginning Programming All-in-One For Dummies. Wallace Wang
Читать онлайн.Название Beginning Programming All-in-One For Dummies
Год выпуска 0
isbn 9781119884422
Автор произведения Wallace Wang
Жанр Программы
Издательство John Wiley & Sons Limited
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.
Writing the same program in the C language makes the program even smaller and much easier to write and understand. If you use a high-level language, the program would most likely require writing less code and be easiest to understand out of them all.
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.
This translation process isn’t perfect, which is why programs written in high-level languages tend to be much bigger and slower than equivalent programs written in machine language or assembly language. So, when programmers want to create large, complicated programs that still run fast and take up as little space as possible, they tend to rely on the C programming language. That’s why so many programs are written in C — C creates programs nearly as small and fast as assembly language programs, while also being nearly as easy to write and understand as high-level languages. (Note the emphasis on the word nearly.)
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.
Figuring Out Programming
After you understand that programming is nothing more than telling a computer how to solve a problem, you may wonder how you can get started figuring out programming on your own. If you want to figure out how to program a computer, this is what you need:
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.
Although it’s possible to figure out programming