While I can easily fix the above syntax error I was curious what my computer was telling me with the word “compile”.
All programming languages can either be interpreted or compiled. There are pros and cons to both approaches. To compile or interpret is to choose how you application translates from the language it was written in (Python, React, Go) to the machine code (binary 0’s and 1’s) that computer hardware can run.
To compile is to pile together all of your application code at once and hand the whole shebang over as an executable file to the computer to run. Now the compiler is proprietary to the language you are using. Languages that are most commonly compiled are C, C++, and Objective C. The compiler is a program that will go through your entire application and convert all of the source code to binary.
Second is an evaluator that uses the AST to execute the program. The tree is a vital data structure at the heart of any interpreter. Depending on the tree structure used a parser can have larger or smaller call stacks which will affect the run time of a parser => interpreter => your program. These very “low level” decisions can have larger impacts depending on the type of program you are running. To learn more about ASTs and Parse trees please check out this dense but awesome blog.
Taking a step back to look at the broader picture what are the pros and cons between a Compiler vs Interpreter? In my research the three factors arise. Speed, code privacy, and cross platform compatibility. A compiler is always going to be faster, because even though it takes extra prep time up front to covert your application program language to machine language(binary), once that is done the machine can take off with all of your code rather than processing one line at a time. A compiler is also going to keep your original source code private because it compiles on your device and just sends an executable file of machine code to the other device running your app. An interpreter is much better for cross platform compatibility because it does not have to create a different executable file for every type of platform and CPU.
- Extra preparation time before starting
- If there is an error in your code it crashes the whole app (failed to compile) so there is there is then the extra step of having to recompile when you need to debug your program (this is a security plus!)
- Have to create specific compilations (binary machine code) for specific platforms (Windows, Mac, Linux) and then create CPU specific binaries within those platform builds
- Runs very fast after initial compilation
- Original source code is kept private because compiler is on your computer and your computer makes a machine code file that is sent to the other device running your program
- Interpreter runs slowly because it interprets and runs program line by line
- Starts right away
- Lets you see your results in real time because one task is executed at a time (EASIER TO DEBUG)
- cross platform so the interpreter program does the heavy lifting of compiling for different platforms etc
That leaves compilers with two out of the three categories but the race is not over. Today many engineers are working to speed up the interpretation process. C# and Java use an Intermediate Language(IL), bytecode is most common example, and a Just In Time Compiler (JiT). This actually allows the programmer to have their original source code kept private because it is just translated to an (IL) which is converted into binary machine code. The machine code is then compiled in the (JiT) which can speed things up and optimize the IL/bytecode even further before it is run as binary on the computer.
Who knows what the future holds as far as coding languages are concerned but I can only see things getting more efficient and complicated from here :)