Is it beneficial for a programmer to learn how to build a compiler?

前端 未结 17 1142
难免孤独
难免孤独 2021-02-07 01:10

There is a lot of variety when it comes to the different types of programmers. In general, is beneficial for a programmer to learn how to build a compiler? In what cases would

17条回答
  •  温柔的废话
    2021-02-07 02:02

    I took two compilers courses in university and found them useful because:

    • Writing a compiler requires knowledge of a lot of areas of computer science - regular expressions, context-free grammars, syntax trees, graphs, etc. It can help you see how to apply the theory of computer science to real-world problems.
    • By understanding how a compiler generates and optimizes code, you will waste less time doing foolish "optimizations" yourself.
    • The process of scanning/lexing a file and building a syntax tree out of it is applicable to a much larger set of problems then just building a compiler.
    • Helps "generalize" programming languages - once you see that every programming language ends up as machine code in the end, it makes it easier to learn new languages because you see that every language is just a different way of expressing the same basic ideas.

    Some people would counter that there are more useful things you could be doing with your time, like learning a popular programming language or library that could help get you a job (this argument is often used as a reason not to learn assembly language). However knowing how compilers work will probably make it easier to learn new programming languages (see point #4).

提交回复
热议问题