Programmers should learn about code compilers.

Source: Internet
Author: User
Programmers should learn about code compilers.

All excellent computer science schools offer compiler courses, but a relatively small number of schools take it as a required part of the undergraduate course. This article answers this question: why do we need to learn compiler knowledge? Even if you have never planned to write a compiler.

One of the reasons I wrote this article is that although I liked the compiler course while I was a bachelor, I could hardly see its actual effect. Most of the information looks either simple or esoteric (in fact, most of the compiler information I have found is boring .) In any case, I spent several years summing up the actual reasons why such courses are so useful. The reasons are as follows.

Analyzer and parser are everywhere

Rigorous php programmers have to understand analyzer and parser, because we don't always write only some small programs. Every time you write an extensible program or process a new type of input files, you need to understand them (Analyzer and parser ). Fig's tenth law:

"After any C or Fortran program is complicated to a certain extent, it will contain a temporary, half-functional, non-fully qualified, bug-filled, and slow-running Common Lisp implementation."

We spend so much time on these things, we can use one-time tips to do everything, or we can use 60 years of theoretical and practical knowledge to solve the problem, and do it right. Important: When should you borrow existing code or use existing tools? When can theoretical knowledge help? What language design principles can be used in our daily use of small languages?

You can better write the correct code

The compiler should correctly translate the input language into a valid program. To achieve this goal, compiler developers must understand the entire input language, including some rare issues that common programmers have never seen. This process of understanding is an important step towards the essence of programming language. it is different from what we usually see when writing code. For example, after learning the details of sequence points, undefined behaviors, and commonly used arithmetic conversions, I completely changed my understanding of C language. C compiler writers have mastered these concepts, but most junior and intermediate programmers do not know them. It is no exaggeration to say that once you know the nature of a language, you will think about it in different ways and more accurately. This applies to any language, especially languages with unclear semantics such as C and C ++.

You can write faster code

By understanding the compiler, you can clearly know which optimizations can be optimized by the compiler, and which ones cannot be optimized, no matter how reasonable and simple they seem. You will learn what kind of code usually creates the best code block and why it does it with the code. You will know why some code can have better performance. for example, if you use a half Register Group to cache the filter coefficient and a half Register Group to cache the sample FIR filter, it is different from the ordinary Optimizer. You and your favorite compiler are a team that can create fast code. you can use it to work efficiently, or use meaningless techniques such as advance optimization to modify it.

Secondly, the back-end of the compiler is closely related to the target architecture. of course, the modern architecture provides a friendly platform for assembler programmers as much as possible, and it is not far away. By understanding the back-end of the compiler and why it generates code like this, you will have a better understanding of the operations on the computer architecture.

Summary

The compiler (theoretically) has three parts:

1. language-related front-end (analysis, type detection)

2. it has nothing to do with the language and goal (optimized ))

3. target-related backend (generate machine code)

In this article, I have tried to convince you that every part of the compiler is valuable-even if you will not implement or modify them in the future.

Get the LAMP brother's original PHP video tutorial CD/detailed PHP Essentials edition for free. for details, contact the customer service on the official website:

Http://www.lampbrother.net


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.