Interpreted languages like Python and Perl have become ubiquitous. It is easier and faster to code in Python than a lower-level language like C, but skipping the compile step also means it's harder to catch syntax or type errors before you run your code.
Luckily, there are ways to check your interpreted code for errors before running. One way is to use an Integrated Development Environment (IDE), such as PyCharm for Python, or a vim plug-in like Syntastic. PyCharm detects errors as you code. Syntastic checks syntax for a variety of languages when you save your file.
You can also check your code from the command line. I will show you how to do this in three popular interpreted languages: Python, Perl, and bash.
Although Python is an interpreted language, it is compiled to bytecode that is then executed by a VM. You might have seen the bytecode as
To compile Python into bytecode without executing, run
python with the
python -m py_compile myprogram.py
myprogram.py contains errors other than logical mistakes, you will catch them in this step.
Compiling is not your only option. The
pylint tool checks syntax, style, and more. To install and use
pip install pylint pylint myprogram.py
Syntax checking Perl is simple. Run the Perl interpreter on your program with the
perl -c myprogram.pl
to check your syntax without running the program.
Bash is not a full-featured programming language like Python or Perl, but it is interpreted and error-prone. Call bash with
-n flag on your script to check its syntax without running it:
bash -n mybashscript.bash