Is it beneficial for a programmer to learn how to

2020-05-31 00:23发布

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 compiler programming be, or not be, needed?

17条回答
Bombasti
2楼-- · 2020-05-31 00:35

Compiler programming is an interesting topic and there is some great value to it. At the college I went to it was an elective, Language Design and Implementation. I'm personally grateful to have taken it. We learned the various ways to implement lexers, parsers, and bytecode emitters.

The real value that I've seen is that it illuminated the black box that I depend on to get my program up and running. It gave me a better insight into how the compiler works, and helped me better understand compiler errors.

The process of compiling source into code is actually in a general way what most programs do, take some input, perform some process, and output the result. A compiler has some very well-defined ideas on how this should best be done.

I think in all it was beneficial to me, and currently I work on Java based web apps.

查看更多
干净又极端
3楼-- · 2020-05-31 00:36

In some ways, this question is a lot like "Should I learn C?"

As others have pointed out, some elements of a compiler — lexical analysis, parsing — can be used in many other applications. You'll learn some useful techniques even if you never have to implement a compiler.

In addition, the code generation phase will give you a better understanding of how the computer works. You'll see how the algorithms and data structures from higher-level languages actually get processed when they get to the CPU (or to the VM, as the case may be). This should help you write better algorithms in your day to day programming.

If you're designing your own language too, then you'll learn a lot through the process of thinking through the details of how it should work, what control flow elements you need, how expressions should be parsed, which order function paramaters should be read, etc. This should give you a better understanding of languages in general, which ought to make you a better programmer in whichever language you use.

Finally, there's always a chance you'll find yourself stuck with a legacy application in an old language that is no longer supported, and the easiest way to add new features will be to build your own compiler to extend the language.

查看更多
地球回转人心会变
4楼-- · 2020-05-31 00:38

I recently did an independent study on what we called Language Processing (my final project was no so much a compiler as a c++ file parser/interpreter with compiler-like features). I was required to use the "Dragon" book that was mentioned above. I thought that as a software developer this was one of the more important things that I have done in my college career. I found it not only interesting and rewarding for my own personal benefit but it also allowed me to see deeper into the language. On top of the because the Dragon book is not language specific it helped me to understand the similarities and more importantly the reasons behind the differences in different languages. I do however agree with the fact that not all programmers may find it necessary. Yet in the field of software development I think that if you have an interest in expanding your understanding of language design it can be very helpful to look at compilers.

查看更多
We Are One
5楼-- · 2020-05-31 00:41

I'm building a compiler as part of one side project and i must say it's a very satisfying task were you'll learn lots about how programming languages work and how code can be optimized.

knowing how code compiles and executes in both native and bytecode is also a great tool in C++ vs Java/C# vs C++/C# vs Java threads and flame wars ;)

查看更多
做个烂人
6楼-- · 2020-05-31 00:43

I learned a lot.

Audrey Tang, developer of PUGS, recommends Types and Programming Languages.

Personally, I loved From NAND to Tetris - probably the best course I've taken, and a shining example of what higher education should be.

查看更多
手持菜刀,她持情操
7楼-- · 2020-05-31 00:45

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).

查看更多
登录 后发表回答